$ is a zero-width end anchor. It matches a position—not a character—at the end of the input. With the m flag, it also matches at the end of each line. Use it to require a suffix.
Remember
/pattern$/ // must finish at end of string
/pattern$/m // end of each line too
/world$/.test("hello world") → true
/world$/.test("world peace") → false
$ consumes nothing (zero-width)
pair with ^ for full-string match: /^…$/
Use
Prefer
Ends with a word
/world$/
End of each line
/end$/m or /end$/gm
File extension
/\.png$/i
Approach
How to Use $
Put $ at the end of the pattern (or before a trailing flag).
Write the text or group that must appear last, then add $ — e.g. /ing$/.
Call test, match, or replace as usual.
Add m when you need the end of every line in multi-line text.
Do not confuse pattern $ with $1 in a replace replacement string.
Piece
Required?
Role
$
Yes
Assert end of string (or line with m)
Suffix pattern
Usual
What must appear just before the end
m flag
Optional
Treat each line end as a match position
Pseudocode
Pseudocode
re = /suffix$/
find "suffix" in text
if found and position after it is end-of-input
(or end-of-line when m is on):
match ✓
else:
fail
// $ itself matches no characters
One line: put $ at the end of a pattern when the match must finish at the end of the string or line.
Frequently Asked Questions
In a pattern, $ is a zero-width end anchor. It matches a position at the end of the input string, or—when the m (multiline) flag is set—immediately before each newline. It does not consume any characters.
No. In a pattern, $ asserts end of string or line. In a replacement string, $1 / $2 refer to capture groups and $$ is a literal dollar. The meaning depends on context.
Use $ with m when your text has newlines and you want the end of each line—not only the very last character of the whole string. Example: /end$/m matches end at the close of every line.
$ matches end of string or line (with m). \b matches a word boundary. /ing\b/ finds a word ending in ing; /ing$/ requires ing at the string or line end.
In JavaScript, $ can also match before a final trailing newline even without m. Prefer testing with your real input, and use m when you need every internal line end.
The $ anchor is core JavaScript regex syntax since ES3. It works in every browser and Node.js version.