Find expression A where expression B follows:
A(?=B)
Find expression A where expression B does not follow:
A(?!B)
Find expression A where expression B precedes:
(?<=B)A
Find expression A where expression B does not precede:
(?<!B)A
An atomic group exits a group and throws away alternative patterns after the first matched pattern inside the group (backtracking is disabled).
(?>foo|foot)sapplied tofootswill match its 1st alternativefoo, then fail assdoes not immediately follow, and stop as backtracking is disabled
A non-atomic group will allow backtracking; if subsequent matching ahead fails, it will backtrack and use alternative patterns until a match for the entire expression is found or all possibilities are exhausted.
(foo|foot)s applied to foots will:
- match its 1st alternative
foo, then fail assdoes not immediately follow infoots, and backtrack to its 2nd alternative; - match its 2nd alternative
foot, then succeed assimmediately follows infoots, and stop.