Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Negate Regex [duplicate]

Possible Duplicate:
Regular expression to match string not containing a word?
How can I invert a regular expression in JavaScript?

Say I have the regex foo123. How do I match everything that is not foo123?

like image 981
StackOverflowNewbie Avatar asked Feb 04 '13 08:02

StackOverflowNewbie


People also ask

How do you use negation in regex?

Similarly, the negation variant of the character class is defined as "[^ ]" (with ^ within the square braces), it matches a single character which is not in the specified or set of possible characters. For example the regular expression [^abc] matches a single character except a or, b or, c.

How do you remove duplicate data flow?

Solution: This problem can be solved by using operators within the Assignment Element in Flow called "Remove Uncommon" and "Remove All". We will use assignment Element to de-duplicate the collection variable so that it can be used to Update/Delete Records.


1 Answers

Use negative lookahead for this.

(?!foo123).+ 

matches any string except foo123

If you want to match empty string also, use (?!foo123).*

In your case (according to the comment) the required regex is (?!P[0-9]{1,}).+.

It matches P and 123, but not P123.

like image 189
Naveed S Avatar answered Sep 18 '22 11:09

Naveed S