regex.go 779 B

1234567891011121314151617181920212223242526272829303132333435
  1. package sprig
  2. import (
  3. "regexp"
  4. )
  5. func regexMatch(regex string, s string) bool {
  6. match, _ := regexp.MatchString(regex, s)
  7. return match
  8. }
  9. func regexFindAll(regex string, s string, n int) []string {
  10. r := regexp.MustCompile(regex)
  11. return r.FindAllString(s, n)
  12. }
  13. func regexFind(regex string, s string) string {
  14. r := regexp.MustCompile(regex)
  15. return r.FindString(s)
  16. }
  17. func regexReplaceAll(regex string, s string, repl string) string {
  18. r := regexp.MustCompile(regex)
  19. return r.ReplaceAllString(s, repl)
  20. }
  21. func regexReplaceAllLiteral(regex string, s string, repl string) string {
  22. r := regexp.MustCompile(regex)
  23. return r.ReplaceAllLiteralString(s, repl)
  24. }
  25. func regexSplit(regex string, s string, n int) []string {
  26. r := regexp.MustCompile(regex)
  27. return r.Split(s, n)
  28. }