diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2019-07-06 17:17:46 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2019-07-06 17:17:46 +0200 |
commit | 1d2ca509c77cbb2af0475b1319cd840f8ce9a1d0 (patch) | |
tree | 05a838baaf4f96fbcce03d06090a2403ee56c878 /re.go | |
parent | 87e820722cf02054225b47a58f97d0824118292f (diff) |
Split in packages
Diffstat (limited to 're.go')
-rw-r--r-- | re.go | 36 |
1 files changed, 0 insertions, 36 deletions
@@ -1,36 +0,0 @@ -package main - -import ( - "errors" - "regexp" - "strings" -) - -var errNotRE = errors.New("not re") - -func re(s, r string, global bool) (string, error) { - // min: at least two separators - if len(r) < 2 { - return "", errNotRE - } - z := strings.Split(r[1:], string(r[0])) - // match // and /// - if len(z) < 2 || len(z) > 3 { - return "", errNotRE - } - re, err := regexp.Compile(z[0]) - if err != nil { - return "", err - } - i := 1 - if global { - i = -1 - } - return re.ReplaceAllStringFunc(s, func(b string) string { - if i != 0 { - i-- - return z[1] - } - return b - }), nil -} |