RegEx subexpression and numeric problem

I have the following string:
abc123xyz

and I want replace the digits (123 in this case) with 3 other digits (456 in this case) every time they follow “abc” and precede “xyz”

So my search pattern is:
(abc)(\d*)(xyz)

So I want the 1st subexpression followed by “456” followed by the 3rd subexpression…

But if I use:
\1456\3

RegEx seems to think that I want the 1456th subexpression followed by the 3rd subexpression and I get junk.

If I use:
\1 456 \3
it works but I get extra spaces that I do not want.

Actually, I am over simplifying this at bit since the “abc” pattern in my actual case has wildcards… it is more like “a.*c”… which is why I have to define it as a subexpression so I can carry it into the resulting replacement string.

So how do you refer to a subexpression in the replacement pattern when it is followed by an integer?

Thanks,
Jim

I haven’t tried this in a while, but what happens if you use a “$” instead of “” in the replacement pattern?

If all else fails, put some symbol into your replacement pattern between the subexpressions that you can remove in Xojo code.

Also, in your search pattern, it should be \\d+ not \\d* or you will match strings without any number at all, unless that’s your intent.

Kem… thanks for the reply but $ does not fix the problem… I think I can use spaces and remove those them after.

RegExRx is a handy tool. Grouping did not work (I ended up with literal parenthesis in the result). For whatever reason, using the “complete match” thing made it work. I’m not certain why, Kem might know, but it does happen to work as you desire:
Replacement Pattern: $&1456$&3

Tim… that gives me:
abc123xyz1456abc123xyz3

I need
abc456xyz

Not sure what you’re doing…

Tim might have found a bug in RegExRX…

Hah oops.

I upgraded my copy of RegExRX and now I get the desired results.

Thank you all,
Jim

It’s not a bug, it’s a feature!

Tagline for Xojo

According to StackOverflow the replacement should be ${1}456${3} but that isn’t working in RegExRx.
https://stackoverflow.com/a/3466924/6047977

Is it RegExRx or is it that Xojo RegEx doesn’t support named groups?

Replacements are not part of the standard so each implementation does its own thing.

[quote=392984:@Tim Parnell]RegExRx is a handy tool. Grouping did not work (I ended up with literal parenthesis in the result). For whatever reason, using the “complete match” thing made it work. I’m not certain why, Kem might know, but it does happen to work as you desire:
Replacement Pattern: $&1456$&3[/quote]

Well this does not seem to work in 2017r2.1… back to the drawing board.

And apparently Xojo’s RegEx doesn’t support named groups. Sounds like you’ll have to use RegEx to find, but do replacement in Xojo code.