Neither-nor oneline REGEXP
Asked Answered
A

1

5

Is it possible to write a regexp rule in "one line" that says: neither A nor B.

For example:

String must contain NEITHER "foo" NOR "bar".

Why one line? Because the filtering tool I am using accepts only one line ... I have tried things like (.*foo.*){0}(.*bar.*){0} without enough luck.

Abecedarium answered 3/6, 2010 at 10:14 Comment(0)
M
9
^(?!.*(foo|bar)).*$
Monocular answered 3/6, 2010 at 10:17 Comment(1)
@Simon negative look-ahead: (?!REGEX_1)REGEX_2 will fail if REGEX_1 matches, but won't consume any characters so that matching of REGEX_2 will start at the same position. There is positive look-ahead (?=REGEX_1)REGEX_2 and their look-behind counter parts. Read regular-expressions.info/lookaround.htmlMonocular

© 2022 - 2024 — McMap. All rights reserved.