Go Package regexp: Difference between revisions
Jump to navigation
Jump to search
Line 38: | Line 38: | ||
==Replacement== | ==Replacement== | ||
Needs a Regexp instance. | |||
===<tt>regexp.ReplaceAllString()</tt>=== | ===<tt>regexp.ReplaceAllString()</tt>=== | ||
<syntaxhighlight lang='go'> | <syntaxhighlight lang='go'> |
Revision as of 16:16, 18 March 2024
External
Internal
Overview
import (
"regexp"
)
var someRegexp *regexp.Regexp
someRegexp = regexp.MustCompile("(\\D+)(\\d+),(\\d)")
groups := someRegexp.FindSubmatch([]byte(s))
if groups == nil {
// no match
...
}
entireString := groups[0]
firstGroup := groups[1]
secondGroup := groups[2]
thirdGroup := groups[3]
Functions
Matching
regexp.MatchString()
Replacement
Needs a Regexp instance.
regexp.ReplaceAllString()
func (re *Regexp) ReplaceAllString(src, repl string) string