Page 1 of 1

Regexp appears to match the whole file name.

PostPosted: Tue Nov 15, 2016 10:56 am
by spalmstr
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.

Re: Regexp appears to match the whole file name.

PostPosted: Tue Nov 15, 2016 11:30 am
by KenP
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

Re: Regexp appears to match the whole file name.

PostPosted: Tue Nov 15, 2016 2:50 pm
by spalmstr
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.

Re: Regexp appears to match the whole file name.

PostPosted: Tue Nov 15, 2016 11:10 pm
by Admin
BRU also supports Javascript (with Regular Expressions), see Special (14)