Regex: Find Every Line that Ends with a Specific Word

To find every line that ends with a specific word, you can use the following regex expression:

^the word$


Let’s say that there’s a specific word you always end your articles with, for example, “as always!”.

But you’ve noticed that in some articles, you have mistakenly added two exclamation marks at the end of the line:

as always!!

That looks silly.

Instead of going through 100s of articles manually to find the sinners, you can simply search for every matching instance of as always!!:

^as always!!$

How the regex code works:

^ and $ are anchors:

  • ^ matches any string that starts with “as”
  • $ matches any string that ends with ”always!!”

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊


Share & Discuss on