Table of Contents

About

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

List

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

Assertion
(?=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

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.

(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}