Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neither-nor oneline REGEXP

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.

like image 437
MartinM Avatar asked Jun 03 '10 10:06

MartinM


People also ask

What is \r and \n in regex?

\n. Matches a newline character. \r. Matches a carriage return character.

How do you match line breaks in regex?

Line breaks In pattern matching, the symbols “^” and “$” match the beginning and end of the full file, not the beginning and end of a line. If you want to indicate a line break when you construct your RegEx, use the sequence “\r\n”.

What does \\ mean in regex?

\\. matches the literal character . . the first backslash is interpreted as an escape character by the Emacs string reader, which combined with the second backslash, inserts a literal backslash character into the string being read. the regular expression engine receives the string \.

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.


1 Answers

^(?!.*(foo|bar)).*$
like image 130
Amarghosh Avatar answered Oct 18 '22 12:10

Amarghosh