Strange double regex replacement

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Strange double regex replacement

Post by *MVV »

You can test it with any file.
Open MRT and try to replace .* with $0_any_text with enabled regex option.
You will see that TC appends _any_text twice.

E.g. original name: Arabic.bin
Search for: .*
Replace with: $0.bak
Expected result: Arabic.bin.bak
Given result: Arabic.bin.bak.bak or Arabic.bak.bak.bin depending on [E] option

BTW if I enable Subst. option, all work fine (but it shouldn't matter here since .* matches entire name anyway).
Also, if I use ^.* instead of .*, all work fine too (but theese should produce similar results in greedy mode which is by default: * matches as many characters as possible).
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

Yes, i noticed that too some time ago. You can see what happens when you add brackets. For example:
Replace with: ($0).bak

I found out that several other regex engines behave the same way. It seems to have to do with the way regex engines are implemented.

Instead of checking the "Subst." option, you can also use the "1x" option which means the same thing in this case.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Wow, it is interesting why second match occurs on empty substring...
Post Reply