Different results between BRU and The Regex Coach

A swapping-ground for Regular Expression syntax

Different results between BRU and The Regex Coach

Postby tinmanjim » Wed Oct 05, 2011 1:06 am

Hi; I'm fairly new to this regex stuff, but enjoy trying to figure things out. To that end, I downloaded 'The Regex Coach', and it seemingly helped me a lot. I say 'seemingly' because when I played around and got a regex expression to do exactly what I wanted in the Coach, I then copied said expression from the Coach and pasted it into the Regex (1) match field. When I then selected the files I wanted to try it on, nothing happened. (I should say that what I'm trying to do is replace part of the middle of a file name with a period (.), so I wrote a regex to match the part I want to delete, and typed a period in the replace field.)
Like I said, nothing happened. Then I typed a period into the replace field, at which point, the entire filename disappeared, leaving in it's place a period.

Here's the current filename:
SC3369-02 - God Bless The U- - S.A. - American Idol Finalists .cdg - .S.A. - American Idol Finalists.mp3
Here's the result I'm after:
SC3369-02 - God Bless The U.S.A. - American Idol Finalists.mp3

Here's the expression that worked in 'The Regex Coach':
Regular expression:
- - (.+)- \.
Replacement string:
.

Worked perfectly in the Coach, not at all (or too well, depending on P.O.V. - what am I missing?
tinmanjim
 
Posts: 2
Joined: Wed Oct 05, 2011 12:46 am

Re: Different results between BRU and The Regex Coach

Postby Glenn » Fri Oct 07, 2011 8:14 am

A couple of observations:
1 - It looks like the first and second filenames differ more than just replacing the 2 dashes with a period. The first one appears to be 2 filenames end to end with another extension in the middle.I assume this is just a copy oversight.
2 - There is a space after the second dash before the letter which follows. This will have to be removed to match the result you say you want.

Bulk rename works a little different from other regex applications in that it needs to capture all parts of the filename that you want in the final result. Most regex apps allow you to replace a segment with something else and the non-matched parts are still left in the result. Not with BRU.

So, assuming all the filenames have only one set of double dashes separated by a space, and possibly another space after the second dash as in your example, try the following:

Match: (.+)- - ?(.+)
The space followed by the ? after the second dash above means it will match 0 or 1 spaces after the dash.
This captures everything before the double dash in \1, and everything following the double dash with optional space after the second dash in \2

Replace: \1.\2
This replaces the original filename with the 2 captured sections separated by a period.

This worked fine in my version of BRU using the filename you supplied.
If you have some variation in the number of spaces surrounding the dashes, you will have to play around with the regex to accommodate this,

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

Re: Different results between BRU and The Regex Coach

Postby tinmanjim » Fri Oct 07, 2011 9:35 pm

Thanks, Glen - that helps a lot. I hadn't noticed the bit about how BRU works a little differently. I have a feeling that armed with that info, I'll be able to figure it out. If I have trouble I will, of course, be back.
By the way, the file name I'm trying to edit is this whole mess:
"SC3369-02 - God Bless The U- - S.A. - American Idol Finalists .cdg - .S.A. - American Idol Finalists.mp3"
I'm trying to delete this part:
"- - S.A. - American Idol Finalists .cdg - "
so that it leaves me with:
"SC3369-02 - God Bless The U.S.A. - American Idol Finalists.mp3"
The problem arose when I tried to use BRU to re-arrange some spaces and dashes; not being aware of the issue you just clued me into, the result was the monstrosity I'm now trying to fix. Now I realize that I simply need to go back to the originals, make another copy of the folder, and do it the right way. (I may not know my way around regex, but I know enough not to work on the originals!)

Thanks again,
Jim
tinmanjim
 
Posts: 2
Joined: Wed Oct 05, 2011 12:46 am


Return to Regular Expressions