Regular Expressions Anchor Characters: Dollar ($) Match a letter at the end of a line or string

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

g$

The above matches one letter (the letter g) at the end of a string in most regex engines (not in Oniguruma, where the $ anchor matches the end of a line by default, and the m (MULTILINE) modifier is used to make a . match any characters including line break characters, as a DOTALL modifier in most other NFA regex flavors). The $ anchor will match the first occurrence of a g letter before the end of the following strings:

In the following sentences, only the letters in bold match:

Anchors are characters that, in fact, do not match any character in a string

Their goal is to match a specific position in that string.

Bob was helping

But his edit introduced examples that were not matching!

In most regular expression flavors, the $ anchor can also match before a newline character or line break character (sequence), in a MULTILINE mode, where $ matches at the end of every line instead of only at the end of a string. For example, using g$ as our regex again, in multiline mode, the italicised characters in the following string would match:

tvxlt obofh necpu riist g\n aelxk zlhdx lyogu vcbke pzyay wtsea wbrju jztg\n drosf ywhed bykie lqmzg wgyhc lg\n qewrx ozrvm jwenx


Got any Regular Expressions Question?