Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

ECMAScript does not correctly parse backreferences with a leading 0 in replacements

Open hueychen27 opened this issue 5 months ago • 4 comments

Bug Description

When using the replacements feature of Regex101, if the substitution regex with $01 is used, it will be treated as literal characters, $, 0, and 1, not the whole backreference of 01 which is the same as 1 in the "Explanation" and hover information.

Reproduction steps

Flavor: "ECMAScript"

Regex: /(d)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)/gm Test: da Substitution regex: $011boom

Expected Outcome

The part which says $01 should be highlighted as a backreference.

Actual: Each character is being treated literally in $01.

Browser

Librewolf version 140.0.4-1

OS

Debian Unstable (Sid)
Regex101 12.2.0

hueychen27 avatar Jul 23 '25 02:07 hueychen27

Hi @hueychen27

Not sure where the explanation is showing $01 as a reference group. This is what I understand you meant. Please advise if different:

Image

working-name avatar Jul 23 '25 05:07 working-name

@working-name Yes, this is what I mean. Sorry if it was not concise enough, you can edit my bug report description since I cannot come up with a different wording.

hueychen27 avatar Jul 23 '25 21:07 hueychen27

Funny syntax, thanks for bringing it to my attention. I'll put it on the back burner :)

firasdib avatar Jul 24 '25 18:07 firasdib

Funny syntax indeed, but it is necessary if you have another number next to it but only want to select the first number. (PCRE2 in Regex101 provides ${} for this purpose)

hueychen27 avatar Jul 24 '25 21:07 hueychen27