veta
veta

Reputation: 736

Regex: Match lines NOT starting with phrase

I found this question about negative lookaheads, but it doesn't work for me in Regexr (which I use to validate regular expressions): Find lines not starting with " in Notepad++

http://www.regexr.com/

I want to match every line that does not start with "Sold, ship now"

Currently, on regexr, when I use the expression ^(?!Sold, ship now) on the following text:

Sold, ship now: [FreeEconomy Shipping]

Sold, NOT ship now: [FreeEconomy Shipping]

Sold, ship now: [FreeEconomy Shipping]

I receive 0 matches.

Upvotes: 3

Views: 4960

Answers (1)

A. Campbell
A. Campbell

Reputation: 414

You'll need to use the multiline flag. Which, in the case of regexr, can be activated like so:

regexr multiline flag

Also, if you'd like to return the entirity of the lines that do not begin with Sold, ship now, I'd recommend utilizing dot plus in your expression:

^(?!Sold, ship now).+

Upvotes: 3

Related Questions