Added example for FindSubmatch
This commit is contained in:
@@ -30,3 +30,25 @@ func ExampleReg_FindAll() {
|
||||
// 3 4
|
||||
// 5 6
|
||||
}
|
||||
|
||||
func ExampleReg_FindString() {
|
||||
regexStr := `\d+`
|
||||
regexComp := regex.MustCompile(regexStr)
|
||||
|
||||
matchStr := regexComp.FindString("The year of our lord, 2025")
|
||||
fmt.Println(matchStr)
|
||||
// Output: 2025
|
||||
}
|
||||
|
||||
func ExampleReg_FindSubmatch() {
|
||||
regexStr := `(\d)\.(\d)(\d)`
|
||||
regexComp := regex.MustCompile(regexStr)
|
||||
|
||||
match, _ := regexComp.FindSubmatch("3.14")
|
||||
fmt.Println(match[0])
|
||||
fmt.Println(match[1])
|
||||
fmt.Println(match[2])
|
||||
// Output: 0 4
|
||||
// 0 1
|
||||
// 2 3
|
||||
}
|
||||
|
Reference in New Issue
Block a user