summaryrefslogtreecommitdiff
path: root/src/pkg/exp/regexp/syntax/compile.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/exp/regexp/syntax/compile.go')
-rw-r--r--src/pkg/exp/regexp/syntax/compile.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/pkg/exp/regexp/syntax/compile.go b/src/pkg/exp/regexp/syntax/compile.go
index ec9556fde..5ea2425c3 100644
--- a/src/pkg/exp/regexp/syntax/compile.go
+++ b/src/pkg/exp/regexp/syntax/compile.go
@@ -86,6 +86,7 @@ func Compile(re *Regexp) (*Prog, os.Error) {
func (c *compiler) init() {
c.p = new(Prog)
+ c.p.NumCap = 2 // implicit ( and ) for whole match $0
c.inst(InstFail)
}
@@ -185,6 +186,10 @@ func (c *compiler) cap(arg uint32) frag {
f := c.inst(InstCapture)
f.out = patchList(f.i << 1)
c.p.Inst[f.i].Arg = arg
+
+ if c.p.NumCap < int(arg)+1 {
+ c.p.NumCap = int(arg) + 1
+ }
return f
}