need help renaming with regular expression

A swapping-ground for Regular Expression syntax

need help renaming with regular expression

Postby howtodothis » Wed Sep 21, 2011 9:05 am

Hi folks,

I need help trying to rename files using regular expressions.

Basically, I have file names that have 4 parts in them and I need to do the following:

From file name: first a_second b.mp3

To file name: first_second.mp3

the file names will have a numbering suffix but that I know how to add it. The extension is also easy.

Any suggestions/help would be much appreciated.

thx
howtodothis
 
Posts: 1
Joined: Wed Sep 21, 2011 8:59 am

Re: need help renaming with regular expression

Postby Glenn » Fri Oct 07, 2011 9:06 am

Assuming all you filenames follow the pattern
first a_second b.mp3
where you want to remove the first space and single character before the first underscore, as well as the next space and any character following it up to the extension dot, the following will work:

Match: ^([^ ]+) \w(_[^ ]+) .\.
The \w will match any letter or number, in case some files contain a number there instead of a letter.

If there is a possibility of more than a single character following the second space before the extension use:
^([^ ]+) \w(_[^ ]+) .+\.

Replace: \1\2

Make sure the Include Ext. box is checked!

You will have to modify it for filenames that do not match the assumptions, but this should get you started.

Cordially,
Glenn
Glenn
 
Posts: 28
Joined: Fri Apr 14, 2006 4:53 pm
Location: Winnipeg, Canada


Return to Regular Expressions