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: capturing group in alternation = crash #4731

gopherbot opened this issue Jan 31, 2013 · 1 comment

regexp: capturing group in alternation = crash #4731

gopherbot opened this issue Jan 31, 2013 · 1 comment


Copy link

@gopherbot gopherbot commented Jan 31, 2013

by myannikos:

If possible, include a link to a program on


What is the expected output?

probably "Qlah"

What do you see instead?

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
regexp.(*Regexp).expand(0xf84004f080, 0xf84004d018, 0x300000003, 0x4b5071,
0x243e623c00000004, ...)
    go/src/pkg/regexp/regexp.go:774 +0x507
regexp._func_001(0x7f27545cbf18, 0x7f27545cbf30, 0x7f27545cbf20, 0x427be5, 0x0, ...)
    go/src/pkg/regexp/regexp.go:429 +0xab
regexp.(*Regexp).replaceAll(0xf84004f080, 0x0, 0x0, 0x4bc2cc, 0x7f2700000010, ...)
    go/src/pkg/regexp/regexp.go:482 +0x471
regexp.(*Regexp).ReplaceAllString(0xf84004f080, 0x4bc2cc, 0xf800000010, 0x4b506c,
0x243e623c00000009, ...)
    go/src/pkg/regexp/regexp.go:430 +0xe3
    /tmpfs/gosandbox-8e586ab1_5059905e_c3c129c6_e0de0f68_13ec3174/prog.go:13 +0xdb

Which compiler are you using (5g, 6g, 8g, gccgo)?


Which operating system are you using?

Debian Squeeze x64

Which version are you using?  (run 'go version')


Please provide any additional information below.

I believe this should not crash, instead $1 should get the value "". A single
unmatched capturing group "(x)" simply does nothing using ReplaceAllString,
putting it in an alternation "b|(x)" should not cause a panic. The panic only
occurs when the other element in the alternation matches.
Copy link

@rsc rsc commented Jan 31, 2013

Comment 1:

Agreed. Fixed at tip.

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
2 participants