Reputation: 19169
In Notepad++, I'm trying to match lines not starting with 32 consecutive spaces.
I already have the regex that matches lines starting with 32 consecutive spaces: ^ {32}.*$
I tried with ^[^ {32}].*$
and ^[^( {32})].*$
with the same wrong result, doesn't match lines with only 24 spaces for example.
Upvotes: 0
Views: 458
Reputation: 22478
Everything inside your straight brackets form a single character class, so
[^ {32}]
matches (not) any of the individual characters ,
{
, 3
, 2
, and }
. The "(not)" is because the first character is a negation. (It does not help.)
What you are looking for is a Negative Lookahead:
^(?! {32}).+$
This tests each line and selects it if it is not followed by at least 32 spaces. To match not only exactly 32 spaces and not more, use another lookahead inside the first one:
^(?! {32}(?! )).+$
Upvotes: 3
Reputation: 5739
Try using a negative lookahead.
(?!^ {32}[^ ]*$)^ +.*$
What the first part(in parentheses) does: It matches a line starting with exactly 32 spaces, and excludes it.
Finally, the second part matches all lines starting with any number of spaces.
Upvotes: 1
Reputation: 138107
Match less than 32 spaces, followed by non-space: http://www.regexr.com/3au2l
^ {0,31}[^ ]
Match "not 32 spaces" using a negative lookahead: http://regexr.com/3au2o
^(?! {32})
In both cases, add .*
to match the whole line, if required.
Upvotes: 2