Baked Inhalf
Baked Inhalf

Reputation: 3735

Regular expression, ignore line when next character is a "-"

If [\s\d]* means: repeat matching space-character or digit. What would be the syntax for ignoring the entire line if there suddenly is a "-" character?

Like in this example https://regex101.com/r/eP1kG1/1 The last line should not match!

.*\bAPPLE.*\bPIE[\s\d]*

SWEET APPLE 1 - PIE 2 SWEET APPLE 1 - PIE 2 IS GOOD SWEET APPLE 1 - PIE3 SWEET APPLE 1 - PIE 1-3 IS GOOD

Only the last line should not match, meaning: When there is a "-" after PIE it should fail.

Also this is for sql, and not possible to use look-ahead/behind

Upvotes: 0

Views: 142

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626794

As I mentioned in my comment, look-aheads usually consume much more computing power. I'd suggest the following regex:

^.*\bAPPLE.*\bPIE[\s\d]*[^-]*$

It just requires all characters after [\s\d]* to be non-hyphens. Anchors - ^ and $ - make sure we only check the whole string.

See demo.

Upvotes: 1

tenub
tenub

Reputation: 3446

Is this what you want? Just checking to make sure PIE[\s\d]* isn't followed by a - on the line:

(?!.*PIE[\s\d]*-).*\bAPPLE.*\bPIE[\s\d]*

Upvotes: 1

Related Questions