Regular expression - Negation

Regexp

About

Regular expression is a language that does not have a NOT operator but it has some negative construct

Construct

Negative Class

^ will negate the class, ie capture until not this characters

Example:

  • matches any character other than a, b, or c.
[^abc]1
  • matches any single character that is not a lowercase letter from a to z. |
[^a-z]1
  • all character except the character p
[^p]*

Negative Look

  • Negative lookahead - do we have a pattern ahead
  • Negative lookbehind - do we have a pattern behind

See Regexp - Look-around group (Assertion) - ( Lookahead | Lookbehind )

Example:

  • Positive lookahead: Capture only if the string has a ?
(?=\?)(.*)





Discover More
Regexp
Regexp - Character Class (Character Set)

A character class defines a domain of permitted characters. character set ASCII characters with square brackets where: [ is the start character class definition ] is the end character class...



Share this page:
Follow us:
Task Runner