Regex
Anchors
Match positions instead of characters.
By EZ4Code Team
anchorboundary
Code
^abc starts with abc
abc$ ends with abc
^abc$ exactly abc
\bword\b word boundary
\B non-word boundary
\A start of string (PCRE)
\z end of string (PCRE)
\Z end of string (before final newline)Explanation
Anchors are zero-width assertions that match a position rather than a character. ^ and $ match the start and end of a line, but with the multiline flag they match at every line boundary. \b matches between a word and a non-word character, while \A and \z always refer to the whole string start and end in PCRE-style engines.
More Regex Snippets
Character Classes
Match sets and ranges of characters.
Quantifiers
Control how many times a token repeats.
Groups and Capturing
Capture, non-capture, and named groups.
Lookaround
Zero-width assertions around a position.
Alternation
Match one of several branches.
Backreferences
Reuse a previously captured group.