Match line not containing a pattern in BBEdit with Grep

3.8k Views Asked by At

I am having trouble finding the correct grep expression for not matching entire lines in BBEdit that do not contain a date, despite having found many "match ... not containing" topics on this on the web...

I have this text document:

Some Text
Some more text,even more text,2015-06-17,2015-06-20
A third line of text
Last line of text, 2015-06-17

This expression will select all lines that contain a date reference, in the form of 4 digits + "-" + 2 digits + "-" + 2 digits

^.*\d\d\d\d-\d\d-\d\d.*$

I would like to match exactly the opposite, with the intention to remove all lines that do not contain a date reference. I have tried solutions like

^.*[^\d\d\d\d-\d\d-\d\d].*$

but with no success so far. Can someone point me in the right direction? Thank you.

2

There are 2 best solutions below

2
On BEST ANSWER

BBEdit supports Perl-Style Pattern Extensions (see page 183 of the manual) including negative lookaheads (?!...).

I believe this will do what you want:

^((?![\d\d\d\d-\d\d-\d\d]).)*$
1
On

One option

"[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"

if you want to exclude the lines that dont have this match its easier to use grep -v