Bug: Regular expressions broken in replace method of version 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.
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.
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
Interesting. Additionally, "\K" no longer works. At least up to version 4.09, which is what I'm using now.
Best,
DF
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.
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.
Reply to #2:
Has \K ever worked?
Has \K ever worked?
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
Hi Kim,
Yes, /K worked in all the version 3.x instances that I have (back at least to 3.88).
Best,
DF