cNb
cNb

Reputation: 67

Regexp matching everything except certain group

I have regexp: /[aA]\/[aA]/,
This regexp catch "a/a", "a/A", "A/A", "A/a"
I need to reverse this procedure and to catch everything except the above examples.
So i found in another answers , that i can use "Negative lookahead".
and try it but without success.
This is what i've try : /(?!([aA]\/[aA]))/

Expected results :
"Some text contaning A/A" - Wrong
"Some text that not contain the above" - Right

Upvotes: 2

Views: 51

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626794

You may use an anchored negative look-ahead:

/^(?!.*a\/a).*$/ig

It will match any line that does not contain a/a (case-insensitively).

See demo

If you have multiline text, replace .* with [\s\S]*.

Upvotes: 1

Related Questions