Added example for 'FindStringSubmatch()'
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user