Moule Lin
← All notes

Positive Lookahead

(?=.?[A-Z]+)(?=.?[a-z])(?=.[!@#$%^&?()])

Checks that the string contains at least one uppercase letter, one lowercase letter and one special character

First, (?=.*?[A-Z]+)

What precedes it here is an empty (zero-width) position, so it matches every empty position that satisfies (?=.*?[A-Z]+)

(?=.?[A-Z]+)(?=.?[a-z])

Here, among the empty positions that already satisfy the first condition, it further matches those that satisfy (?=.*?[a-z])

(?=.?[A-Z]+)(?=.?[a-z])(?=.[!@#$%^&?()])

Likewise

^.(?=.{6,16})(?=.\d)(?=.[A-Z]{2,})(?=.[a-z]{2,})(?=.[!@#$%^&?()]).*$

Negative lookahead

(?!)

Positive lookbehind: right to left

(?<=)

Negative lookbehind

(?<!)