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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login