pkg "regexp" not have function which allow many group replace, only have
ReplaceAllString
// ReplaceAllString returns a copy of src, replacing matches of the Regexp
// with the replacement string repl. Inside repl, $ signs are interpreted as
// in Expand, so for instance $1 represents the text of the first submatch.
func (re *Regexp) ReplaceAllString(src, repl string) string {
n := 2
if strings.Contains(repl, "$") {
n = 2 * (re.numSubexp + 1)
}
b := re.replaceAll(nil, src, n, func(dst []byte, match []int) []byte {
return re.expand(dst, repl, nil, src, match)
})
return string(b)
}
I looking for way to do replace with additional option `1$1|$2|$3`
среда, 2 сентября 2020 г., 23:23:40 UTC+3 пользователь Brian Candler
написал:
>
> Can you define the problem more clearly?
>
> It looks like you just want to replace a leading "9", "001" or "+1" with
> "1"? In that case, you just match ^(9|001|[+]1) and replace it with 1
>
> If that's not what you want, then what are the exact rules for how the
> input needs to be changed?
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/ce8acf0c-f6c9-419d-a477-3463fc1e8eefo%40googlegroups.com.