Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: add Split #2762

Closed
gopherbot opened this issue Jan 23, 2012 · 5 comments
Closed

regexp: add Split #2762

gopherbot opened this issue Jan 23, 2012 · 5 comments
Milestone

Comments

@gopherbot
Copy link

by raul.san@sent.com:

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
}
@dsymonds
Copy link
Contributor

Comment 1:

Labels changed: added priority-someday, packagechange, removed priority-triage.

@rsc
Copy link
Contributor

rsc commented Jan 29, 2012

Comment 2:

Labels changed: added priority-later, removed priority-someday.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 3:

Labels changed: added go1.1.

@gopherbot
Copy link
Author

Comment 4 by rickarnoldjr:

Fixed by: https://golang.org/cl/6846048/

@rsc
Copy link
Contributor

rsc commented Nov 27, 2012

Comment 5:

This issue was closed by revision 94b3f6d.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants