Regular Expression Replacing (Not Filter)

Would you like Bulk Rename Utility to offer new functionality? Post your comments here!

Regular Expression Replacing (Not Filter)

Postby oniisaki » Sun Jun 08, 2014 7:15 pm

BRU is a great tool, but I find it lacking with regular expression (box 1), which has alot of potential for advanced file renaming.
I find the current regex usage more like a filtering tool which uses regex to check for if there any matches to the file/folder name (i.e. test with regex),
then replace the whole file/folder name with specified character if any matches.

I think instead of replacing the whole filename, it should have an option (maybe a checkbox) to
only replace the parts of the filename that has matched the regular expression.

Also, another dandy feature of regex is perhaps to allow it to reorder words/matches in folder/file names,
Such as below demonstrated in vbscript code:

Code: Select all
Set regEx = New RegExp
str = "First Second"
regEx.Pattern = "(\S+)(\s+)(\S+)"
regEx.IgnoreCase = True

str=regex.Replace(str, "$3$2$1")
'$1 correspond to the 1st bracket indicated in the pattern at line 3 - (\S+)
'$2 correspond to the 2nd bracket indicated in the pattern at line 3 - (\s+)
'$3 correspond to the 3rd bracket indicated in the pattern at line 3 - (\S+)
WScript.Echo str

RESULT:
Second First

Note:
To run the above code under windows, copy the code into a newly created text file,
rename the text file to have extension of "vbs", then click on it.

Alternatively, if your not of vbscript background, you can go to this link and see how it demonstrates(and explains) the re-ordering with regex process:
http://regex101.com/r/yH9kL0
oniisaki
 
Posts: 2
Joined: Sun Jun 08, 2014 6:51 pm

Regex

Postby truth » Tue Jun 10, 2014 2:34 am

To only replace specifically matched chars, you can use:
(.*)YourMatch(.*)
\1YourReplace\2

No part of OrigName outside YourMatch is touched.
BRU imposes no restriction on the ordering of replacements.
So \1YourReplace\2 is just as valid as \2YourReplace\2\1\2, etc.

BRU's regex doesnt employ global-matching, but it has #3Replace & CharTrans.
Both settings perform as a global match/replace if needed.
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay

Re: Regular Expression Replacing (Not Filter)

Postby oniisaki » Tue Jun 10, 2014 2:27 pm

Thanks for the information.
Didn't think I had to use "\1" instead of "$1" to work with BRU regex replacing.

But for tasks such as removing information contained in brackets/braces, such as:
[Info]Name(Info)[Info]
Name(Info)[Info]
[Info]Name(Info)

I'm finding it difficult (but possible now with your provided information)
to use BRU regex to remove those information in brackets.

For tasks like these, I really do wish BRU regex supports global and parts replacing
to make things a lot easier.
oniisaki
 
Posts: 2
Joined: Sun Jun 08, 2014 6:51 pm

Re: Regular Expression Replacing (Not Filter)

Postby truth » Thu Jun 12, 2014 8:55 am

Yes, a global-checkbox would make a nice regex-enhancement!
For now, the best way to remove [AnyText] or {Anytext} or (AnyText):
(.*)(\[.*\]|\{.*\}|\(.*\))(.*)
\1\3

It only removes the last-occurence of [AnyText] or {AnyText} or (AnyText)
so it must be run multiple-times to remove any multiple-occurences.

The commandline version doesnt have this 1Regex-per-run limitation,
so its far-better suited for this task (till we have a global-checkbox).
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay

Re: Regular Expression Replacing (Not Filter)

Postby Eepoonioo » Mon Sep 22, 2014 7:58 am

While I agree that the current regex-replace in BRU is ridiculous, the solution is simply to use the STANDARD way of doing regex-replace.

See details in my post here: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=2&t=2336

Basically BRU is not doing it in the standard way. Other regex file renamers (eg. RegexRenamer, Advanced Renamer) use the standard way which does not require matching the *entire* filename. You just match the string you want to replace. For example, getting rid of "%20", "%3A" etc. url string in filenames:

STANDARD regex string to find them = "%..". Run that once and it's done.

BRU's requirement: "(.*?)%..(.*?)%..(.*?)%.." with "\1\2\3" for however many there are. But what about multiple files with different numbers of occurrences? That's simply impossible to do in BRU, unless you run "(.*?)%..(.*)" with "\1\2" MULTIPLE TIMES. Plain silly.

I haven't seen any other application (or programming language) which requires you to match the entire string when you're doing a simple regex replace for a little substring. BRU needs to implement the standard approach like every other app out there.
Eepoonioo
 
Posts: 4
Joined: Mon Sep 22, 2014 4:43 am


Return to Suggestions


cron