Search code examples
grepbbedit

Match line not containing a pattern in BBEdit with Grep


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.


Solution

  • 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]).)*$