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

gopherbot opened this issue Jan 23, 2012 · 5 comments

regexp: add Split #2762

gopherbot opened this issue Jan 23, 2012 · 5 comments


Copy link

@gopherbot gopherbot commented Jan 23, 2012


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":


func RegexpSplit(s, r string) []string {
splitter := regexp.MustCompile(r)
matches := splitter.FindAllStringIndex(s, -1)
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
Copy link

@dsymonds dsymonds commented Jan 23, 2012

Comment 1:

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

Copy link

@rsc rsc commented Jan 29, 2012

Comment 2:

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

Status changed to Accepted.

Copy link

@rsc rsc commented Sep 12, 2012

Comment 3:

Labels changed: added go1.1.

Copy link

@gopherbot gopherbot commented Nov 13, 2012

Comment 4 by rickarnoldjr:

Fixed by:
Copy link

@rsc 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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.