Go Package regexp: Difference between revisions
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
* [[Go_Language_Modularization#regexp|Standard Library]] | * [[Go_Language_Modularization#regexp|Standard Library]] | ||
=Overview= | |||
<syntaxhighlight lang='go'> | |||
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] | |||
</syntaxhighlight> | |||
=Functions= | =Functions= |
Revision as of 01:36, 11 January 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]