bug in backreferences replacement

A place to try and solve your RegEx problems.
Post Reply
User avatar
PaulD

bug in backreferences replacement

Post by PaulD »

Hi
Great application BTW, looking to replace Funduc S&R with this!

Using $1 in replacement string does not work if followed by a digit.

Example search text: "<idt>201002</idt>"

This works:
Search regex: "<idt>(\d{6})</idt>"
Replace regex: "<idt>$1xx</idt>"
Expected result: "<idt>201002xx</idt>"
Result: "<idt>201002xx</idt>"

This does not work:
Search regex: "<idt>(\d{6})</idt>"
Replace regex: "<idt>$101</idt>"
Expected result: "<idt>20100201</idt>"
Result: "<idt>$101</idt>"

Maybe the backreference matcher is looking for number 101 instead of number 1?

The same Regex works in Microsoft Word 2003 VBA, using Microsoft VBScript Regular Expressions 5.5 (vbscript.dll/3)

Tx
User avatar
DV

Post by DV »

Yes, it's looking for 101 in that case.
You can put the number in braces-
eg:
<idt>${1}01</idt>

This will work now!

Glad you like the software!
User avatar
DV

Post by DV »

Interestly, your broken example works if you put TextCrawler into ECMAscript compatible mode (eg The same as VBA/Javascript).
User avatar
PaulD

Post by PaulD »

Great, both options work, thanks DV.
Post Reply