diff --git a/regex/example_test.go b/regex/example_test.go index d652ca7..2360a03 100644 --- a/regex/example_test.go +++ b/regex/example_test.go @@ -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)