简体   繁体   中英

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

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]* .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM