Bug: Regular expressions broken in replace method of version 4

Advanced Renamer forum
#1 : 01/04-25 23:01
Just A Suggestion
Posts: 4
Regular expressions do not work correctly in version 4 (currently tested with v4.11).

Filename: test.txt
Replace: .*
Replace with: _
Incorrect result: __.txt
Expected: _.txt

.* should consume the whole string and replace it with exactly one character in this example.
But there is some strange duplication of replacement taking place at the start and the end of the matched string.

Making the quantifier lazy *? leads to the string not even being replaced anymore. Instead of replacing the four individual characters of "test" each with a "_" five characters are inserted surrounding the original characters.

Filename: test.txt
Replace: .*?
Replace with: _
Incorrect result: _t_e_s_t_.txt
Expected: ____.txt

If one were to use the quantifier + instead of * the delivered results would be as expected in both cases.
However .+ is not the same as .* and .* is the (second) most basic regular expression. It should be fixed.

Filename: test.txt
Replace: .+
Replace with: _
Correct result: _.txt

Filename: test.txt
Replace: .+?
Replace with: _
Correct result: ____.txt

Based on the above, there seems to be something wrong with the way the * quantifier is handled.

If one were to use ^.*$ instead of .* the result would be as expected. But this is not a valid workaround, because anchoring is not always possible and additionally increases the complexity of the regular expression and hence the readability.

It would be nice to have this fixed in a future version of Advanced Renamer.

edited: 01/04-25 23:08
#2 : 02/04-25 00:51
Delta Foxtrot
Posts: 458
Reply to #1:

Interesting. Additionally, "\K" no longer works. At least up to version 4.09, which is what I'm using now.

Best,
DF
#3 : 02/04-25 07:22
Kim Jensen
Administrator
Posts: 977
Reply to #1:
Have you tried changing the "Occurrence" dropdown to "1st"? I know it seems a little counter intuitive, but on a technical level it makes sense.
#4 : 02/04-25 09:34
Kim Jensen
Administrator
Posts: 977
Reply to #2:
Has \K ever worked?
#5 : 02/04-25 13:46
Delta Foxtrot
Posts: 458
Reply to #4:

Hi Kim,

Yes, /K worked in all the version 3.x instances that I have (back at least to 3.88).

Best,
DF