Reputation: 8119
I want to find all lines without a double number.
I know how to find the double number on a line:
/\zs\(\d\d\d\.\d\d\).*\1\ze
But I don't know how to find lines without this double number (the negative matching of above regex)
This one does partially what I want:
/^\(\(.*\d\d\d\.\d\d.*\)\{2,}\)\@!.*\1.*$
p.e.:
the line 201.12 text 201.12
is NOT found --> OK
but also the line 201.12 text 203.12
is NOT found --> NOT OK
Last line has to be found because the numbers are NOT the same.
What did I wrong?
Upvotes: 1
Views: 83
Reputation: 9445
Try this one:
/^.*$\&\%(.*\(\d\{3}\.\d\{2}\).*\1\)\@!.*
or with magic:
/\v^.*&%(.*(\d{3}\.\d{2}).*\1)@!.*
Actually, \&
is no need. This one is simpler:
\v^%(.*(\d{3}\.\d{2}).*\1)@!.*
Upvotes: 2
Reputation: 785481
This one is a bit tricky. Here is lookahead based pattern that lets you do that assuming each line has 2 decimal numbers:
/\v^((\d{3}\.\d{2})@!.)*(\d{3}\.\d{2})(.*\3)@!.*
Upvotes: 1
Reputation: 1783
I'd go with this:
.*(\d\d\d\.\d\d).*(?=\d\d\d\.\d\d)(?!\1).*
The ?= is a not consuming operator. It looks for the regex on the right side of the equals symbol but leaves it to be checked by the following expressions. Because of this it test the string again. Then it checks if the first match is included. If it is found, the query fails (because of the?!) - if it is not found it goes ahead to the next .*
Upvotes: 1