git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/validate/utils_example_test.go (about) 1 package validate 2 3 func ExampleTrim() { 4 // Remove from left and right spaces and "\r", "\n", "\t" characters 5 println(Trim(" \r\r\ntext\r \t\n", "") == "text") 6 // Remove from left and right characters that are between "1" and "8". 7 // "1-8" is like full list "12345678". 8 println(Trim("1234567890987654321", "1-8") == "909") 9 } 10 11 func ExampleWhiteList() { 12 // Remove all characters from string ignoring characters between "a" and "z" 13 println(WhiteList("a3a43a5a4a3a2a23a4a5a4a3a4", "a-z") == "aaaaaaaaaaaa") 14 } 15 16 func ExampleReplacePattern() { 17 // Replace in "http123123ftp://git534543hub.comio" following (pattern "(ftp|io|[0-9]+)"): 18 // - Sequence "ftp". 19 // - Sequence "io". 20 // - Sequence of digits. 21 // with empty string. 22 println(ReplacePattern("http123123ftp://git534543hub.comio", "(ftp|io|[0-9]+)", "") == "http://github.com") 23 }