help with the regex interface

A swapping-ground for Regular Expression syntax

help with the regex interface

Postby chewmanfoo » Tue Feb 18, 2014 12:05 am

I have a few file names of this format:

Code: Select all
Session 1 Schematic (1999 - 2011).avi
Session 1 Notes (1999).doc
Session 2 Notes (2011).doc
Session 6.avi


I would like to strip off the end of every file name from the opening parenthesis to the end, if the file name has a parenthesis.

I know the proper regex for this is something like:

Code: Select all
\(.*$


When I put that in the regex Match box, nothing happens. When I add a > to Replace I see:

Code: Select all
>.avi
>.doc
>.doc
Session 6.avi


That seems logical since the first three match and the last does not. How do I use the regex field to capture all files with an opening parenthesis, and replace the opening parenthesis to the end of the file name with nothing, but leave file names without a parenthesis unaffected?

Thanks in advance!
chewmanfoo
 
Posts: 1
Joined: Mon Feb 17, 2014 11:55 pm

Re: help with the regex interface

Postby truth » Tue Feb 18, 2014 2:17 am

To preserve text within OrigName, you must group it (within parenthesis)
and then reference that same text with \1, \2, etc in your replacement.
1Regex match/replace:
(.+) \(.*
\1

The (.+) groups all text until a final Space(Anything
\1 references that text for NewName

No $ after .* is needed, except to further spec how filenames should end.
Ex: For filenames with parenthesis that also end as )
(.+) \(.*\)$
\1

BRUs regex wont touch filenames not matched by the expression in its MatchBox.
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay


Return to Regular Expressions