Regex Look-Ahead/Back

This is a tricky topic, but here's the best explanation I found:

* (?=) - Positive look ahead assertion foo(?=bar) matches foo when followed by bar

* (?!) - Negative look ahead assertion foo(?!bar) matches foo when not followed by bar

* (?<=) - Positive look behind assertion (?<=foo)bar matches bar when preceded by foo * (? - Negative look behind assertion (? * (?>) - Once-only subpatterns (?>\d+)bar Performance enhancing when bar not present

* (?(x)) - Conditional subpatterns

* (?(3)foo|fu)bar - Matches foo if 3rd subpattern has matched, fu if not

* (?#) - Comment (?# Pattern does x y or z)


Example: I was looking for ABCabc123 in "apple/banana/ABCabc123"

regular expression: (?<=apple/banana/)\\w+(?=\")

No comments: