From d522f50b502f77c536a23bea4a259b80a3fe3153 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 9 Feb 2025 15:40:59 -0500 Subject: [PATCH] Wrote new example functions --- regex/example_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/regex/example_test.go b/regex/example_test.go index f2443a2..60ed033 100644 --- a/regex/example_test.go +++ b/regex/example_test.go @@ -52,3 +52,29 @@ func ExampleReg_FindSubmatch() { // 0 1 // 2 3 } + +func ExampleReg_Expand() { + inputStr := `option1: value1 + option2: value2` + regexStr := `(\w+): (\w+)` + templateStr := "$1 = $2\n" + regexComp := regex.MustCompile(regexStr, regex.RE_MULTILINE) + result := "" + for _, submatches := range regexComp.FindAllSubmatch(inputStr) { + result = regexComp.Expand(result, templateStr, inputStr, submatches) + } + fmt.Println(result) + // Output: option1 = value1 + // option2 = value2 + +} + +func ExampleReg_LiteralPrefix() { + regexStr := `a(b|c)d*` + regexComp := regex.MustCompile(regexStr) + prefix, complete := regexComp.LiteralPrefix() + fmt.Println(prefix) + fmt.Println(complete) + // Output: a + // false +}