Trịnh Anh Ngọc
Trịnh Anh Ngọc

Reputation: 113

(Vim regex) Following by anything except bracket character

Test string:

best.string_a = true;
best.string_b + bad.string_c;
best.string_d ();
best.string_e );

I want to catch string that after '.' and followed by anything except '('. My expression:

\.\@<=[_a-z]\+\(\s*[^(]\)\@=

I want :

string_a
string_b
string_c
string_e

But it doesn't work and result :

string_a
string_b
string_c
string_d
string_e

I am new to vim regex and i dont know why :(

Upvotes: 2

Views: 517

Answers (2)

Kent
Kent

Reputation: 195039

this would work for your needs too:

\.\zs[_a-z]\+\>\ze\s*[^( ]

Upvotes: 1

Christian Brabandt
Christian Brabandt

Reputation: 8248

Make this \.\@<=\<[_a-z]\+\>\(\s*(\)\@!

This matches:

\.\@<=          Assure a dot is in front of the match followed by
\<[_a-z]\+\>    A word containing only lowercase or '_' chars
\(\s*(\)\@!     not followed by (any amount of spaces in front of a '(')

Upvotes: 2

Related Questions