Created
December 2, 2017 11:03
-
-
Save wader/bd548cc5f20cc8650cc7739832d76db5 to your computer and use it in GitHub Desktop.
go regexp replace capture group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func replace(content string, re *regexp.Regexp, s string) (string, string) { | |
| v := re.FindStringSubmatchIndex(content) | |
| if v == nil { | |
| return content, "" | |
| } | |
| p0 := v[2] | |
| p1 := v[3] | |
| return content[0:p0] + s + content[p1:], content[p0:p1] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment