#1 2007-04-13 22:56

waholayo
Member
Registered: 2007-04-13
Posts: 3

Does ReNamer's Regular Expression support Assertions?

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

#2 2007-04-15 03:48

waholayo
Member
Registered: 2007-04-13
Posts: 3

Re: Does ReNamer's Regular Expression support Assertions?

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

#3 2007-04-22 09:07

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Does ReNamer's Regular Expression support Assertions?

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

#4 2007-05-12 09:50

waholayo
Member
Registered: 2007-04-13
Posts: 3

Re: Does ReNamer's Regular Expression support Assertions?

Thanks for your reply. I'll be looking forward for future releases. big_smile

Offline

#5 2007-05-12 17:14

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Does ReNamer's Regular Expression support Assertions?

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

Board footer

Powered by FluxBB