RegEx help - find & replace specific word at the end of a line
-
I have a text file which contains all of my game titles. Titles that begin with the word ‘The’ are recorded as:
First Tree, The.
This was done purely for alphabetical sorting purposes. However there are some occasions when it would be useful to have it listed normally (The First Tree).
I would like:
Find: “First Tree, The”
Replace with: “The First Tree”But only do so when the word ‘the’ happens to be the last word in the title. Is there a RegEx find & replace method for such occurrences?
-
-
But only do so when the word ‘the’ happens to be the last word in the title.
You didn’t tell us how to know if it’s the last word in the title. Is that indicated by a period, like you showed in your first example? Or an end-of-line? Or something else?
Assuming it’s a period (and you want to keep the period):
- FIND =
(?-s)^(.+), (The)\.
- REPLACE =
$2 $1.
- SEARCH MODE = Regular Expression
----
Useful References
- FIND =
-
@Alan-Kilborn said in RegEx help - find & replace specific word at the end of a line:
Find: (?-s)^(.+?), The$
Replace: The ${1}That’s exactly it! Thank you Alan.