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

1 - About

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

3 - 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

3.1 - 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,}


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap