Regexp appears to match the whole file name.

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Regexp appears to match the whole file name.

Postby spalmstr » Tue Nov 15, 2016 10:56 am

I attempted to replace all the spaces and brackets in a filename by underscores.

Regexp: [\s()]

Replacement: _

Old file name "some name.ext"
New file name "_.ext"

What is going wrong? I thought the regular expression should just match the spaces or brackets and replace them. That is how I've experienced using regular expressions in various programming languages.
spalmstr
 
Posts: 2
Joined: Tue Nov 15, 2016 10:49 am

Re: Regexp appears to match the whole file name.

Postby KenP » Tue Nov 15, 2016 11:30 am

Regex in BRU doesn't work like that, you need to capture parts of the file name in groups then reuse or rearrange the groups to rename the files.

From what you've said it seems that the file names do not all follow the same format in which case your best bet would be to use "Character Translations".

Special (14)
Click on the icon under Character Translations and a dialogue box will open, in that box write the following strings, each character translation on a separate line.
[=_
]=_
=_


If you want to do it with regex the file names will need to be in a similar format, for the example you've given this will work.
RegEx (1)
Match: (\S+)\s(\S+)
Replace: \1_\2
KenP
 
Posts: 199
Joined: Sat Jul 30, 2016 11:25 am

Re: Regexp appears to match the whole file name.

Postby spalmstr » Tue Nov 15, 2016 2:50 pm

Thanks. I had hope it might follow the rules of something like replace(regex, source, text_to_replace) where the command simply replaced the matching characters.
spalmstr
 
Posts: 2
Joined: Tue Nov 15, 2016 10:49 am

Re: Regexp appears to match the whole file name.

Postby Admin » Tue Nov 15, 2016 11:10 pm

BRU also supports Javascript (with Regular Expressions), see Special (14)
Admin
Site Admin
 
Posts: 2341
Joined: Tue Mar 08, 2005 8:39 pm


Return to BRU Support