Added example for 'FindStringSubmatch()'

implementBackreferences
Aadhavan Srinivasan 4 weeks ago
parent 525296f239
commit c803e45415

@ -35,7 +35,7 @@ func ExampleReg_FindString() {
regexStr := `\d+`
regexComp := regex.MustCompile(regexStr)
matchStr := regexComp.FindString("The year of our lord, 2025")
matchStr := regexComp.FindString("The year is 2025")
fmt.Println(matchStr)
// Output: 2025
}
@ -53,6 +53,18 @@ func ExampleReg_FindSubmatch() {
// 2 3
}
func ExampleReg_FindStringSubmatch() {
regexStr := `(\d{4})-(\d{2})-(\d{2})`
regexComp := regex.MustCompile(regexStr)
inputStr := `The date is 2025-02-10`
match := regexComp.FindStringSubmatch(inputStr)
fmt.Println(match[1])
fmt.Println(match[3])
// Output: 2025
// 10
}
func ExampleReg_FindAllSubmatch() {
regexStr := `(\d)\.(\d)(\d)`
regexComp := regex.MustCompile(regexStr)

Loading…
Cancel
Save