Remove from a start word to a end character

A swapping-ground for Regular Expression syntax

Remove from a start word to a end character

Postby Sandy » Mon Feb 28, 2011 10:47 am

Hi,
Could someone please help on how I can use BRU to rename files from this

aaaaa bbbbb feat. cccccc dddddd - eeeeeee.mp3

to

aaaaa bbbbb - eeeeeee.mp3

So everything from feat. to the space before the - needs to be removed.

cccccc dddddd can be any length.

Thanks.
Sandy
 
Posts: 3
Joined: Mon Feb 28, 2011 10:27 am

Re: Remove from a start word to a end character

Postby Stefan » Mon Feb 28, 2011 4:46 pm

Welcome,

FROM:
aaaaa bbbbb feat. cccccc dddddd - eeeeeee.mp3
TO:
aaaaa bbbbb - eeeeeee.mp3

DO:

RegEx(1)
Match: (.+) feat\. .+ (- .+)
Repla: \1\2


Explanation:
"(.+)" =====> match one-or-more of any sign ===> "aaaaa bbbbb" and store this in group (1)
" feat" ==> match an space, followed by literal "feat" ===> " feat"
"\." ====> followed by an dot ==> "."
" .+ " ===> followed by one space and one-or-more of any sign and an space ==> " cccccc dddddd "
"(- .+)" => match an dash followed by an space and one-or-more of any sign ===> "- eeeeeee" and store in group (2)

Note: " feat. cccccc dddddd " is not stored into an group because we want to get rid of this part anyway.

Then replace with was is matched and stored in group 1 and group 2
\1\2



untested but should work


Note that based on your example i just use " feat" and "- " as anchor point to catch the position to split the parts.

If there are more then one of each of this two anchors in the string my regex will fail.
If not, then even this simpler regex may work too:
Match: (.+) feat.+ (- .+)
Repla: \1\2
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Remove from a start word to a end character

Postby Sandy » Mon Feb 28, 2011 8:45 pm

Thanks for the reply Stefan,
I've tried your answer and it's very close to what I need except it's removing one too many spaces,

aaaaa bbbbb feat. cccccc dddddd - eeeeeee.mp3

Is renamed to

aaaaa bbbbb- eeeeeee.mp3

Is there any way it can be renamed to

aaaaa bbbbb - eeeeeee.mp3

Thanks.
Sandy
 
Posts: 3
Joined: Mon Feb 28, 2011 10:27 am

Re: Remove from a start word to a end character

Postby Sandy » Mon Feb 28, 2011 8:51 pm

I've worked it out.
What I need is :

RegEx(1)
Match: (.+)feat\. .+ (- .+)
Repla: \1\2
Sandy
 
Posts: 3
Joined: Mon Feb 28, 2011 10:27 am


Return to Regular Expressions