summaryrefslogtreecommitdiff
path: root/regexp/regexp.go
diff options
context:
space:
mode:
Diffstat (limited to 'regexp/regexp.go')
-rw-r--r--regexp/regexp.go44
1 files changed, 40 insertions, 4 deletions
diff --git a/regexp/regexp.go b/regexp/regexp.go
index 8aeaa43c..a6cadc74 100644
--- a/regexp/regexp.go
+++ b/regexp/regexp.go
@@ -2,10 +2,22 @@ package regexp
import stdre "regexp"
-// Replace -
-func Replace(expression, replacement, input string) string {
- re := stdre.MustCompile(expression)
- return re.ReplaceAllString(input, replacement)
+// Find -
+func Find(expression, input string) (string, error) {
+ re, err := stdre.Compile(expression)
+ if err != nil {
+ return "", err
+ }
+ return re.FindString(input), nil
+}
+
+// FindAll -
+func FindAll(expression string, n int, input string) ([]string, error) {
+ re, err := stdre.Compile(expression)
+ if err != nil {
+ return nil, err
+ }
+ return re.FindAllString(input, n), nil
}
// Match -
@@ -13,3 +25,27 @@ func Match(expression, input string) bool {
re := stdre.MustCompile(expression)
return re.MatchString(input)
}
+
+// Replace -
+func Replace(expression, replacement, input string) string {
+ re := stdre.MustCompile(expression)
+ return re.ReplaceAllString(input, replacement)
+}
+
+// ReplaceLiteral -
+func ReplaceLiteral(expression, replacement, input string) (string, error) {
+ re, err := stdre.Compile(expression)
+ if err != nil {
+ return "", err
+ }
+ return re.ReplaceAllLiteralString(input, replacement), nil
+}
+
+// Split -
+func Split(expression string, n int, input string) ([]string, error) {
+ re, err := stdre.Compile(expression)
+ if err != nil {
+ return nil, err
+ }
+ return re.Split(input, n), nil
+}