Search code examples
regexregex-lookaroundsregexp-replace

Regex Dot to End of Line


I have a txt document with too many lines. What I want to do is a bit complicated. For example, I want to reach the end of each line containing the word thing and put a period there. But only at the end of the lines that contain the word thing.

Example : regexr.com/64ehm


Solution

  • In fact, the regular expression you could use to do that is quite simple. This, along with the global and multiline flags, would match lines that contain only the word thing:

    ^Thing$
    

    If you don't want to distinguish uppercase from lowercase letters, the case insensitive flag can help you.

    After getting the lines you're looking for, you can use the means available in your programming language or tool to put a period at each line's end.

    You can also test that regular expression in RegExr.