Remove only - as first character?

A swapping-ground for Regular Expression syntax

Remove only - as first character?

Postby penbrock » Sat May 30, 2015 3:03 pm

I was able to find the expression here to remove the track number from the start of my songs and it worked great for the most part.

How ever now I have a few files that start with a '-'.

How to I remove the '-' ONLY if it is the first character in the file name?
penbrock
 
Posts: 3
Joined: Sat May 30, 2015 2:58 pm

Re: Remove only - as first character?

Postby bitmonger » Sun May 31, 2015 5:57 pm

There are a multiple ways to do this:
One is:
Set Selections(12) to -*.*
This will cause BRU to display only filenames starting with a single hyphen

Set Remove(5) First n to 1
This removes that hyphen.

Another way is:
Regex (1)

Match: ^-(.+)
Matches all filenames starting with a hyphen (the ^ means the start of the filename), saving everything after the hyphen as \1

Replace: \1
Include Ext box NOT checked

Hope this helps,
Bit
bitmonger
 
Posts: 50
Joined: Sat Sep 22, 2007 5:05 am

Re: Remove only - as first character?

Postby penbrock » Sun May 31, 2015 7:58 pm

Thank you First option works great.

2nd option I think I had tried but it removed the first '-' any where in the name. In (song)-(group).mp3 it also removed

Thanks again
penbrock
 
Posts: 3
Joined: Sat May 30, 2015 2:58 pm

Re: Remove only - as first character?

Postby bitmonger » Sun May 31, 2015 9:13 pm

I'm not sure why the second method didn't work for you. I tested it on filenames with multiple hyphens throughout and it only changed those with a leading hyphen, and only removed the lead hyphen.(I included the (song)-(group).mp3 name you mentioned as well and it didn't change it.)
I have a suspicion you may have one of the other fields checked which is removing non-leading hyphens.
bitmonger
 
Posts: 50
Joined: Sat Sep 22, 2007 5:05 am

Re: Remove only leading (first character) hyphen minus dash

Postby Stefan » Mon Jun 01, 2015 7:32 am

 
No, penbrock had missed (or wrongly tried to include) the leading ^ sign.

Advise to penbrock: try to copy the whole match expression bitmonger shown you   ^-(.+)   and paste it into BRU.

Then it works as indented.





 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Remove only - as first character?

Postby penbrock » Mon Jun 01, 2015 11:41 am

That must have been it. I must have missed the ^
penbrock
 
Posts: 3
Joined: Sat May 30, 2015 2:58 pm


Return to Regular Expressions