Version 4+

Advanced Renamer forum
#1 : 26/10-24 13:10
Jeffery Suan
Posts: 1
I am having troubles using all of my 3.95 renaming method lists with version 4+. I always get the error 'Invalid Regular Expression'.

From trying to isolate things, I did find a place where it says, for example:
* TRegExpr compile: unrecognized modifier (pos 14)

This led me to assume the new Version is using TRegExpr. Following that lead I found myself at https://regex.sorokin.engineer/ which contained some documentation for the library.

However, even when using specific examples listed in the documentation, such as:

Positive lookahead assertion: foo(?=bar) matches "foo" only before "bar", and "bar" is excluded from the match.

This still produced * TRegExpr compile: unrecognized modifier (pos 09).

So I was wondering if I could get confirmation on the flavor of Regex being used and any other insight to assist in converting method lists to work in 4+ versions.

Thank you in advance for your time.
#2 : 26/10-24 15:28
Delta Foxtrot
Posts: 458
Reply to #1:

That would certainly be useful information. I've always avoided lookaround in ARen because I could never remember what worked and what didn't in v.3.x
:)
#3 : 09/04-25 15:28
Chris Hart
Posts: 4
Reply to #2:
I have an expression: ^.*?(?=\_)
It replaces the text before the underscore with new text.

Works in the 3.94p version. Doesn't work in the 4.11p version.

Any ideas how to fix it? I am not good with RegEx and it took me a long time to get this right in the first place.

Thank you
#4 : 09/04-25 15:50
Chris Hart
Posts: 4
Reply to #3:
Got it figured out, not sure how it works, but it does: ^(.*?)\_*

Hope this helps someone else eventually
#5 : 09/04-25 15:50
Delta Foxtrot
Posts: 458
Reply to #3:

Hi Chris,

In both versions you can use
Replace: ^.*?_
Replace with: Any-text_
Regex checked

If there's only one underscore in your filenames just use ^.*_
(again, both versions)

Best,
DF

EDIT: Sorry, didn't see you'd replied to yourself. :) But still, as you create more complex method batches and regular expressions, it's good to understand how to simplify your expressions. For instance, if you aren't going to reuse something there's very little reason to capture it in parentheses. Also, underscore never needs to be escaped, because it's not significant to any regex engine I know of. It's considered just another word character like an A or b.

edited: 09/04-25 16:03
#6 : 09/04-25 16:10
Chris Hart
Posts: 4
Reply to #5:
I tried it. I was logging in to say my solution didn't work.

This solution basically works, but it includes the underscore, and I need everything before the underscore - leaving the underscore in place. There are 26 individual operations after this, and the previous RegEx kept the underscore.

Essentially, I have filenames like: Raw1247B_Each01.psd
I need to change that to: Eat a Joe's_Each01.psd

Previously I had: ^.*?(?=\_) and it worked splendidly.
#7 : 09/04-25 16:25
Chris Hart
Posts: 4
Reply to #6:
I think I got it!!!

^[^\_]+

Not sure why the + fixes it, but it seem to work.
#8 : 09/04-25 16:33
Delta Foxtrot
Posts: 458
Reply to #7:

Chris,

Referring to your message #6, I'm not sure what the problem is.

Replace: ^.*_
With: Eat a Joe's_

Gives me exactly what you said you wanted (in v4 and v3) in the example filename.

As to your new expression, the "+" says match 1 or more (not zero) occurrences of the previous character class or sequence (in this case the character class [^_], so it matches any character except an underscore up to any number of times, stopping the match before the underscore. If you have a filename starting with an underscore it won't work.

edited: 09/04-25 16:35