Remove leading characters keeping name

A swapping-ground for Regular Expression syntax

Remove leading characters keeping name

Postby ocman » Wed Nov 02, 2011 10:13 pm

hey all, apologies if this has been posted, I've been searching and can't find it anywhere.

Here is the issue.
Thousands of music files that I have to rename, and its taking me a very long time.

Files that are like this:
12 - Duran Duran - Wild Boys.mp3

I want to be like this:
Duran Duran - Wild Boys.mp3

problem is its not always:
12 - Duran Duran

its also
04 - Duran Duran
02 - Fallout Boys
231 - Bruce Springsteen

any help would be appreciated.
Basically I want to remove anything, including spaces before the first Letter in the file name begins. No matter how many characters are before the name.

Thank you in advance for any help.
ocman
 
Posts: 1
Joined: Wed Nov 02, 2011 10:00 pm

Re: Remove leading characters keeping name

Postby Stefan » Fri Nov 04, 2011 11:16 pm

Try

RegEx(1)
Match: '\d+ - (.+)'
Repla: \1


Means:
\d ===> match one digits
+ ===> match one-or-more of the last expression, here the \d
' - ' ===> match space, hyphen, space
(.+) ===> match one-or-more of any sign, and store it in group one, which match can be accessed by '\1' in the replacement.





----------------------

I don't know why this works too in BRU. Because that is wrong expression, it should match only one digit, space, hyphen, space...:
RegEx(1)
Match: '\d - (.+)'
Repla: \1
Stefan
 
Posts: 508
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Remove leading characters keeping name

Postby Glenn » Sun Nov 06, 2011 6:17 pm

Hi Stefan,
Nice work on the regex.

I think the reason it (\d) still works is because the regex still matches part of the line.

for example, in the line below the \d - will match the 2 - . The (.+) matches the rest.

12 - Duran Duran - Wild Boys.mp3

It's true that it doesn't match the whole line but we aren't capturing anything before the \d so it is ignored and dropped when the replacement takes place.
i.e. as long as the complete regex matches within the line it will work, even if that match doesn't include the whole line.

It does make a difference (won't match) if we change the regex to
^\d - (.+)
In this case it is trying to force a match with a single leading digit beginning at the start of the line.
This is probably what you were thinking when you wondering why it would still work with a single \d.

Cheers,
Glenn
Glenn
 
Posts: 26
Joined: Fri Apr 14, 2006 4:53 pm
Location: Winnipeg, Canada


Return to Regular Expressions