Regex Anchors

Learn how to force the regex engine to start or end at a fixed position.

It’s important to know how the regex engine handles greedy matches, but it’s equally as important to know what kind of matches we want. Regex anchors force the regex engine to start or end a match at a fixed position.

Start and end anchors

The start of string anchor \A dictates that any match must start at the beginning of the string:

Get hands-on with 1200+ tech skills courses.