You are not logged in.
First I would like to thank Denis Kozlov, the author of the ReNamer. This program has one of the best interface and feature, such as the concept of "rule" and preview window. Thanks so much and even make it free of charge.:)
I've been trying to use assertions (e.g. ?=, ?!, ?<=, ?!=, ?<!, ?>, ?(condition)then|else) in RegEx rules, however it does not work as expected. (reference)
I use ReNamer 4.60.
Ex:
When applying the below RegEx rule to remove all duplicated [ or ]:
Replace expression "([\[\]])(?=$1)" with ""
on files:
[[][].txt
[[tag][tag]].txt
[tag1]][[tag2].txt
It returns a empty string which wipes out all characters in the file name:
.txt
.txt
.txt
Same result (empty file name) even if change the rule to below for testing:
Replace expression "([\[\]])(?=$1)" with "$1"
These are the expected results:
[][].txt
[tag][tag].txt
[tag1][tag2].txt
Therefore I am have to use the following rule:
Replace expression "(\[){2,}|(\]){2,}" with "$1$2"
My conclusion is that RegEx assertions are currently not supported in ReNamer 4.60.
Will assertions be supported in the future?
Offline
Found a better solution which takes very few steps to match and to fail, also with low backtrack.
Replace expression "([\[\]])\1+" with "$1"
The interesting thing here is: the expression string accepts only the backslash style, \1, for back reference, while the replace string takes only the Perl style, $1.
Just in case if anyone got frustrated or confused when using backreferences, but could not get it to work.
Offline
Glad that you've found a solution!
I will add a note in help files about backreferences in the regular expressions.
About assertions.. you are right, they are not yet supported in the reg ex implementation that I'm using.
Offline
Thanks for your reply. I'll be looking forward for future releases.
Offline
By the way, PascalScript can do all those assertions (if/else), and it has 2 RegEx functions:
function ReplaceRegEx(const Input, Find, Replace: WideString; const CaseSensitive, UseSubstitution: Boolean): WideString;
function MatchesRegEx(const Input, Find: WideString; const CaseSensitive: Boolean): TStringsArray;
Offline