|
|
|
@ -52,3 +52,29 @@ func ExampleReg_FindSubmatch() {
|
|
|
|
|
// 0 1
|
|
|
|
|
// 2 3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExampleReg_Expand() {
|
|
|
|
|
inputStr := `option1: value1
|
|
|
|
|
option2: value2`
|
|
|
|
|
regexStr := `(\w+): (\w+)`
|
|
|
|
|
templateStr := "$1 = $2\n"
|
|
|
|
|
regexComp := regex.MustCompile(regexStr, regex.RE_MULTILINE)
|
|
|
|
|
result := ""
|
|
|
|
|
for _, submatches := range regexComp.FindAllSubmatch(inputStr) {
|
|
|
|
|
result = regexComp.Expand(result, templateStr, inputStr, submatches)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(result)
|
|
|
|
|
// Output: option1 = value1
|
|
|
|
|
// option2 = value2
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExampleReg_LiteralPrefix() {
|
|
|
|
|
regexStr := `a(b|c)d*`
|
|
|
|
|
regexComp := regex.MustCompile(regexStr)
|
|
|
|
|
prefix, complete := regexComp.LiteralPrefix()
|
|
|
|
|
fmt.Println(prefix)
|
|
|
|
|
fmt.Println(complete)
|
|
|
|
|
// Output: a
|
|
|
|
|
// false
|
|
|
|
|
}
|
|
|
|
|