Added function and examples for ReplaceAllFunc()

This commit is contained in:
2025-02-10 21:35:51 -05:00
parent 3b7257c921
commit 073f231b89
2 changed files with 33 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package regex_test
import (
"fmt"
"strings"
"gitea.twomorecents.org/Rockingcool/kleingrep/regex"
)
@@ -167,6 +168,14 @@ func ExampleReg_ReplaceAllLiteral() {
regexStr := `fox|dog`
inputStr := "the quick brown fox jumped over the lazy dog"
regexComp := regex.MustCompile(regexStr)
fmt.Println(regexComp.ReplaceAll(inputStr, `duck`))
fmt.Println(regexComp.ReplaceAllLiteral(inputStr, `duck`))
// Output: the quick brown duck jumped over the lazy duck
}
func ExampleReg_ReplaceAllFunc() {
regexStr := `\w{5,}`
inputStr := `all five or more letter words in this string are capitalized`
regexComp := regex.MustCompile(regexStr)
fmt.Println(regexComp.ReplaceAllFunc(inputStr, strings.ToUpper))
// Output: all five or more LETTER WORDS in this STRING are CAPITALIZED
}