Other Escape Sequences and Assertions
Learn about some escape sequences and assertions.
Other escape sequences
To match a literal instance of a metacharacter, escape it with a backslash \
. We’ve seen this before, where \(
refers to a single left parenthesis and \]
refers
to a single right square bracket. \.
refers to a literal period character instead
of the “match anything but an explicit newline character” atom.
Remember to escape the alternation metacharacter |
, as well as the end-of-line metacharacter $
and the quantifiers +
, ?
, and *
if you want to match their symbols literally.
The metacharacter disabling characters (\Q
and \E
) disable metacharacter
interpretation within their boundaries. This is especially useful when we
don’t control the source of the matched text:
Get hands-on with 1400+ tech skills courses.