...

Package regex

import "simonwaldherr.de/go/golibs/regex"
Overview
Index
Examples

Overview ▾

regex is a wrapper for the standard regexp package. It automates the regexp.Compile process for you.

func CacheRegex

func CacheRegex(regex string) error

func CheckRegex

func CheckRegex(regex string) error

func Cleanup

func Cleanup()

func Count

func Count() int

func FindAllString

func FindAllString(src, regex string) ([]string, error)

FindAllString returns a slice of all strings holding the text of the leftmost match in src of the regular expression. If there is no match, the return value is nil. It will be empty if the regular expression successfully matches an empty string.

func FindAllStringSubmatch

func FindAllStringSubmatch(src, regex string) ([][]string, error)

FindAllStringSubmatch returns a slice of a slice of strings holding the text of the leftmost match of the regular expression in src and the matches. A return value of nil indicates no match.

func MatchString

func MatchString(src, regex string) (bool, error)

func ReplaceAllString

func ReplaceAllString(src, regex, replace string) (string, error)

ReplaceAllString returns a copy of src, replacing matches of the regular expression with the replacement string replace. Inside replace, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.

Example

Code:

str, _ := regex.ReplaceAllString("FooBaR LoReM IpSuM", "[a-z]", "")
fmt.Print(str)

Output:

FBR LRM ISM

func ReplaceAllStringFunc

func ReplaceAllStringFunc(src, regex string, replace func(s string) string) (string, error)

ReplaceAllStringFunc returns a copy of src in which all matches of the regular expression have been replaced by the return value of function replace applied to the matched substring. The replacement returned by replace is substituted directly, without using Expand.