Moving ",The" and losing the comma

A swapping-ground for Regular Expression syntax

Moving ",The" and losing the comma

Postby dmizesr » Sat Dec 31, 2011 3:11 am

I have a few files mixed in among others that end in ", The" as in "Night of the Living Dead, The". What I want is "The Night of the Living Dead." So, being a regex dummy, how do I do this?

Thanks in advance.

DWM
dmizesr
 
Posts: 1
Joined: Sat Dec 31, 2011 3:07 am

Re: Moving ",The" and losing the comma

Postby Stefan » Sun Jan 01, 2012 7:34 pm

dmizesr wrote:FROM:
"Night of the Living Dead, The"

TO:
"The Night of the Living Dead."



Try this

RegEx(1)
Match: (.+), [tT]he$
Repla: The \1


Explanation:
Code: Select all
(.+)      ==> find one-or-more of any sign
, [tT]he  ==> but only till found: an coma followed by an space followed by any case 'T' and 'he'
$         ==> be sure that that 'The' is found only at the end of the file name and don't match on something like
                  "Night of the Living Dead, The word" or "Night of the Living Dead, Theater version"

The       ==> added by hand on your own
\1        ==> get back what is matched by the first (...) capturing group ==> "(.+)"




HTH? :D
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Moving ",The" and losing the comma

Postby dalben » Thu Nov 15, 2012 4:36 pm

How would you reverse it ?

i.e. "The Filename.ext" to "Filename, The.ext"

Edit: Actually, I managed to work that out:

Find: ^(The)\s(.+)$
Replace: \2, \1

But where I am coming unstuck is where some file names have a (1234) at the end.

So I need the following

"The Filename.ext" to "Filename, The.ext" and "The FIlename (1234).ext" to "Filename, The (1234).ext"
dalben
 
Posts: 5
Joined: Thu Jan 26, 2012 8:38 am


Return to Regular Expressions