From: Nikolai Weibull Date: 2004-09-23T10:05:18+09:00 Subject: Re: Regexp Arity * Florian Frank [Sep 23, 2004 03:00]: > > > > Regexp#groups ? > > > > Regexp#groupcount? > > > Regexp#ngroups > > Best by far, so far, > Which groups are counted here? There are capturing groups and > non-capturing groups. Or is this the sum of those two numbers? Precisely why it isn't great. > At the moment I don't see any obvious reason to count those > groups in a Regexp at all. I should know everything about them > before I created the regexp. If I want to find out how many > captures I got after matching the regexp I can easily get that > info from MatchData#captures.size. > On the other hand the grouping is a tree structure and if I simply > compute one number from a regexp I loose a lot of information. They can > be quite complicated like /(((a))(?:(b|c)|d))/. From the group > size alone I cannot infer very much about the values that will be > captured after a match. Simons tree construction example makes > much more sense if one wants to examine the structure of > a regexp. The only viable thing to do is return exactly the number of capturing groups given, not excluding anything. If you wish to write a regex such as yours above, then you are in it for the trouble. I agree with you, however, that designing based on the knowledge of how many capturing groups are in a regex isn't very good design at all. nikolai -- ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka ::: ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden ::: ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 ::: main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}