summaryrefslogtreecommitdiff
path: root/re.go
blob: 90a9fdabd334caac5a97b2da5540934000930b5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
	"regexp"
	"strings"
)

func re(s, r string) string {
	// min: s//
	if len(r) < 3 || r[0] != 's' {
		return ""
	}
	z := strings.Split(r[2:], string(r[1]))
	// match s// and s///
	if len(z) < 2 || len(z) > 3 {
		return ""
	}
	re, err := regexp.Compile(z[0])
	if err != nil {
		return ""
	}
	return re.ReplaceAllString(s, z[1])
}