Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace with regex: capturing group #1477

Open
sekedus opened this issue Nov 24, 2024 · 1 comment
Open

Replace with regex: capturing group #1477

sekedus opened this issue Nov 24, 2024 · 1 comment

Comments

@sekedus
Copy link

sekedus commented Nov 24, 2024

Describe the issue

Output result when replace using searchbox with regex are not the same as the result from JavaScript.

  1. with searchbox: big_a1id_hide_a0aca1_fa2ag_a3-m

screenshot-codemirror_net-2024_11_24-20_29_25

  1. with JS: big_kid_hide_jack_flag_a3-m
const str = 'abcdefghijklm';
const rgx = /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)/i;
const rpl = "$2$9$7_$11$9$4_$8$9$4$5_$10$1$3$11_$6$12$1$7_$13-";
const result = str.replace(rgx, rpl);

// Output: big_kid_hide_jack_flag_a3-m
console.log(result);

Browser and platform

Google Chrome 128.0.6613.138 (64-bit)

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge2phdmFzY3JpcHR9IGZyb20gIkBjb2RlbWlycm9yL2xhbmctamF2YXNjcmlwdCIKCm5ldyBFZGl0b3JWaWV3KHsKICBkb2M6IGBjb25zdCBzdHIgPSAnXHg2MVx4NjJceDYzXHg2NFx4NjVceDY2XHg2N1x4NjhceDY5XHg2YVx4NmJceDZjXHg2ZCc7CmNvbnN0IHJneCA9IC8oYSkoYikoYykoZCkoZSkoZikoZykoaCkoaSkoaikoaykobCkvaTsKY29uc3QgcnBsID0gIiQyJDkkN18kMTEkOSQ0XyQ4JDkkNCQ1XyQxMCQxJDMkMTFfJDYkMTIkMSQ3XyQxMy0iOwpjb25zdCByZXN1bHQgPSBzdHIucmVwbGFjZShyZ3gsIHJwbCk7CgovLyBPdXRwdXQ6IGJpZ19raWRfaGlkZV9qYWNrX2ZsYWdfYTMtbQpjb25zb2xlLmxvZyhyZXN1bHQpO2AsCiAgZXh0ZW5zaW9uczogW2Jhc2ljU2V0dXAsIGphdmFzY3JpcHQoKV0sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5Cn0pCgovLyBvdXRwdXQ6IGFiY2RlZmdoaWprbG0=

@marijnh
Copy link
Member

marijnh commented Nov 24, 2024

Output result when replace using searchbox with regex are not the same as the result from JavaScript.

That is true. But I don't think our docs promise that this works the same anywhere. Did you run into a practical issue caused by this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants