summaryrefslogtreecommitdiff
path: root/re.go
diff options
context:
space:
mode:
Diffstat (limited to 're.go')
-rw-r--r--re.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/re.go b/re.go
index d2461ab..4d3fa48 100644
--- a/re.go
+++ b/re.go
@@ -1,23 +1,26 @@
package main
import (
+ "errors"
"regexp"
"strings"
)
-func re(s, r string, global bool) string {
+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 ""
+ return "", ErrNotRE
}
z := strings.Split(r[1:], string(r[0]))
// match // and ///
if len(z) < 2 || len(z) > 3 {
- return ""
+ return "", ErrNotRE
}
re, err := regexp.Compile(z[0])
if err != nil {
- return ""
+ return "", err
}
i := 1
if global {
@@ -29,5 +32,5 @@ func re(s, r string, global bool) string {
return z[1]
}
return b
- })
+ }), nil
}