What will the '$' regular expression match?
The regex \$ matches a literal dollar sign character, not the end of a
string. The plain $ metacharacter is the end-of-line/end-of-string anchor in
many regex flavors, while \$ escapes it so it is treated as an ordinary
character.
What it means
$by itself usually matches the position at the end of a line or string.
\$matches an actual$symbol in the text.
- In engines that support multiline mode,
$can also match before a line break at the end of a line.
Example
- Pattern:
price\$ - Matches:
price$ - Does not match:
priceUSD
Small caution
Regex behavior can vary a bit by engine, especially around line breaks and
multiline mode, but the core rule is the same: escaped $ means a literal
dollar sign.