From fd102292c63dc1e04d061cfc59ce297d0a54a40f Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sat, 1 Feb 2025 18:05:43 -0500 Subject: [PATCH] Added example for FindSubmatch --- regex/example_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/regex/example_test.go b/regex/example_test.go index 9a881c5..f2443a2 100644 --- a/regex/example_test.go +++ b/regex/example_test.go @@ -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 +}