firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.2k stars 198 forks source link

Golang replace string edge case #2289

Open FrancescoLuzzi opened 3 weeks ago

FrancescoLuzzi commented 3 weeks ago

Bug Description

Can't replace a string with a new string containing a $ inside it. The golang docs on regexp.ReplaceAllString and regexp.Expand states that in this case you should use $$

Reproduction steps

Expected Outcome

The substitution pattern should not error and return the modified string

Pretty sure this is a logic error, if you still need browser and os infos let me know

working-name commented 3 weeks ago

Go example run to recreate the edge case described: https://go.dev/play/p/TveUE4pFo6L?v=goprev

FrancescoLuzzi commented 3 weeks ago

Also this one https://go.dev/play/p/tv5Q7FFkt0v

In a nutshell, when you want to escape the capture group placeholders in a replaceString, instead of writing something like "\$" you'll need to write "$$"