Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match 0 or more than 1 occurence of whitespace

Tags:

regex

vim

I want to use regex to match the following strings:

blub{ (no intervening space) and blub  { (two intervening spaces) and blub   { (three intervening spaces) and so on but not blub { (one intervening space)

In the moment I can match blub{ with /\S{/ and the rest with /\S \{2,}{/ in my vimrc file. However I cannot combine these to regex expressions in vim. How can I achieve this?

The aim is to mark in my cpp files all lines where the bracket has not a space between.

like image 499
tune2fs Avatar asked Dec 20 '12 09:12

tune2fs


People also ask

Is used for zero or more occurrences in regex?

A regular expression followed by an asterisk ( * ) matches zero or more occurrences of the regular expression. If there is any choice, the first matching string in a line is used.

Which regex matches one or more digits?

+: one or more ( 1+ ), e.g., [0-9]+ matches one or more digits such as '123' , '000' . *: zero or more ( 0+ ), e.g., [0-9]* matches zero or more digits. It accepts all those in [0-9]+ plus the empty string.

What is the regex for white space?

The RegExp \s Metacharacter in JavaScript is used to find the whitespace characters. The whitespace character can be a space/tab/new line/vertical character. It is same as [ \t\n\r].

What is used to match anything except a whitespace?

[^ ] matches anything but a space character.


1 Answers

Use alternatives.

/\S\(\| \{2,}\){/
like image 57
kmkaplan Avatar answered Sep 22 '22 13:09

kmkaplan