You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
strings.Split() is limited to a simple string but you could want to split when a regular
expression is matched up. (To add in package regexp)
This was add into a post (untested) by "chrisfarms":
import(
"regexp"
)
func RegexpSplit(s, r string) []string {
splitter := regexp.MustCompile(r)
matches := splitter.FindAllStringIndex(s, -1)
fmt.Println(matches)
start := 0
end := 0
strings := make([]string, 0)
for i := 0; i<len(matches)+1; i++ {
if i>len(matches)-1 {
end = len(s)
} else {
end = matches[i][0]
}
strings = append(strings, s[start:end])
if i<=len(matches)-1 {
start = matches[i][1]
}
}
return strings
}
The text was updated successfully, but these errors were encountered:
by raul.san@sent.com:
The text was updated successfully, but these errors were encountered: