From 6b23b77e390673e086731e93a8dada9d02f64587 Mon Sep 17 00:00:00 2001 From: Peter Froehlich Date: Thu, 24 Dec 2009 08:43:35 +1100 Subject: Add query to find number of subexpressions. This was convenient for me to have without being forced to parse the regexp myself. I'd understand if it's not really wanted, but I also think that some meta information about compiled regexps would be fine. R=r, rsc CC=golang-dev http://codereview.appspot.com/183044 Committer: Rob Pike --- src/pkg/regexp/regexp.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pkg/regexp/regexp.go') diff --git a/src/pkg/regexp/regexp.go b/src/pkg/regexp/regexp.go index fd6fbefee..373d6b1af 100644 --- a/src/pkg/regexp/regexp.go +++ b/src/pkg/regexp/regexp.go @@ -677,6 +677,9 @@ func MustCompile(str string) *Regexp { return regexp } +// NumSubexp returns the number of parenthesized subexpressions in this Regexp. +func (re *Regexp) NumSubexp() int { return re.nbra } + // The match arena allows us to reduce the garbage generated by tossing // match vectors away as we execute. Matches are ref counted and returned // to a free list when no longer active. Increases a simple benchmark by 22X. -- cgit v1.2.3