O que é uma declaração de expressão regular?
Uma asserção é uma expressão regular que é bem-sucedida (se uma correspondência for encontrada) ou falha (se uma correspondência não for encontrada).
Eles consistem em Âncoras e Lookarounds.
Âncoras
An Anchor is a zero-width Assertion. They do not cause the engine to advance through the string or consume characters, and can be one of the following:
^
- The match must start at the beginning of the string or line.
$
- The match must occur at the end of the string or before \n at the end of the line or string.
\A
- The match must occur at the start of the string.
\Z
- The match must occur at the end of the string or before \n at the end of the string.
\z
- The match must occur at the end of the string.
\G
- The match must occur at the point where the previous match ended.
\b
- The match must occur on a boundary between a\w
(alphanumeric) and a\W
(nonalphanumeric) character.
\B
- The match must not occur on a\b
boundary.
Origem Idioma de expressão regular - Referência rápida
Lookarounds
Asserções Lookahead e Lookbehind Zero-LengthLookahead and lookbehind, collectively called "lookaround", are zero-length assertions just like the start and end of line, and start and end of word anchors.
The difference is that lookaround actually matches characters, but then gives up the match, returning only the result: match or no match. That is why they are called "assertions". They do not consume characters in the string, but only assert whether a match is possible or not.
Lookaround allows you to create regular expressions that are impossible to create without them, or that would get very longwinded without them.
Fonte Dominando Lookahead e Lookbehind