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


Look-around are non-capturing group that implements an assertion.


If you don't find your pattern below, question mark has other functionality in regular expression. See them all at Regular Expression - Question Mark (?)

(?=X) X, positive lookahead (via zero-width)
(?!X) X, negative lookahead (via zero-width)
(?<=X) X, positive lookbehind (via zero-width)
(?<!X) X, negative lookbehind (via zero-width)

where X is a sub-regular expression


Lookahead is typically used to create a logical operator AND between two regular expressions.

For example, if a password must:

  • contain:
    • a lower case letter,
    • an upper case letter,
    • a punctuation symbol,
  • and be at least 6 characters long

then the following expression can be used to validate the password.


Powered by ComboStrap