RegEx Bug?

Hello once again. I am trying to validate if I am just making a bonehead move or have hit a RegEx replace bug in 2013 R3.3.
I get the desired results of a match/replace pattern with Kem’s RegExRx Tool.

My Code has the exact same Options as RegExRx however Xojo doesn’t match correctly.
Xojo matches:

Any help is always appreciated. Thanks!

I’m not going to pretend I’m good with RegEx, but it appears the search patterns are different. The RegExRx pattern is “\d[:]|(?<=[,]).[:]" while yours is "\d[:]|(?<=\,).[:]” so the [,] in the RegExRx is \, in your code. Maybe that is the problem?

No, the slash just makes it a literal, so it wouldn’t matter. I’ll test this in a second Mike, but FYI, you don’t need the square brackets around either the colon or the comma. You only need square brackets when it’s a choice of tokens, like if you were looking to match a colon or a comma.

Ok that’s good to know, like I said I’m no RegEx expert, was just pointing out the difference I saw .

Looks like you found a bug Mike. I can’t get that pattern to work right either, even though the matches are correct. Your alternatives are to cycle through the matches and reassemble the string yourself, use other Xojo code to replace your text (like Split in a loop), or use RegExMBS which works perfectly.

OK, this pattern does work:

"(?mi-Us)\\d:|,\\K[^:]*:"

A couple of things: “." should be avoided when possible because it’s too general. In this case, I substituted "[^:]”, which means, zero or more characters that are not a colon, which is what you really want.

“\K” is a more advanced token, so you don’t see it much. It means, reset the start of the match, so even though it matches the comma, the \K discards it and starts the match from that point.

I just tested it in Xojo and it works like a charm.

Thanks Kem!!! Phew I was beating my head on then wall and unlike your RegEx skills I couldn’t find another pattern to work when I hit the bug :slight_smile: Thank you again!!

Kem your pattern works like a Charm thank you again. I will also file a feedback case on this.

<https://xojo.com/issue/31120>