Added function and examples for ReplaceAllFunc()
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user