You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When replacing a string with a match group, if any text is put after the replacement, all text is ignore afterwards. regex replacements work as expected for $1 bar while $1bar does not.
This is working as documented. Inside the documentation for the function you called, ReplaceAllString, it says:
Inside repl, $ signs are interpreted as in Expand,
and then the Expand documentation says:
In the template, a variable is denoted by a substring of the form $name or ${name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the submatch with the corresponding index; other names refer to capturing parentheses named with the (?P...) syntax. A reference to an out of range or unmatched index or a name that is not present in the regular expression is replaced with an empty slice.
In the $name form, name is taken to be as long as possible: $1x is equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0.
Go version
go version go1.20.2 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
When replacing a string with a match group, if any text is put after the replacement, all text is ignore afterwards.
regex
replacements work as expected for$1 bar
while$1bar
does not.bug example
What did you see happen?
When using regex replacements, if any word (\w+) is used after the replacement, the complete text is ignored
outputs:
.baz
What did you expect to see?
Given that the above example, I would expect it to return
foobar.baz
The text was updated successfully, but these errors were encountered: