![]() |
Regexp Arity
Just ran into a need to know how many parenthetical groupings a Regexp has.
Would #arity for Regexp be a good idea? T. |
Re: Regexp Arity
Hi,
In message "Re: Regexp Arity" on Thu, 23 Sep 2004 03:26:44 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes: |Just ran into a need to know how many parenthetical groupings a Regexp has. |Would #arity for Regexp be a good idea? I'm not sure if it should be named 'arity'. matz. |
Re: Regexp Arity
On Thu, 23 Sep 2004 03:54:31 +0900, Yukihiro Matsumoto
<matz@ruby-lang.org> wrote: > In message "Re: Regexp Arity" > on Thu, 23 Sep 2004 03:26:44 +0900, "trans. (T. Onoma)" <transami@runbox.com> > |Just ran into a need to know how many parenthetical groupings a Regexp has. > |Would #arity for Regexp be a good idea? > I'm not sure if it should be named 'arity'. Regexp#groups ? Regexp#groupcount? -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca : as of this email, I have [ 6 ] Gmail invitations |
Re: Regexp Arity
On Wednesday 22 September 2004 20:26, trans. (T. Onoma) wrote:
> Just ran into a need to know how many parenthetical groupings a Regexp has. > Would #arity for Regexp be a good idea? hmm... irb(main):006:0> parser = Parser.new('a(b(?:c(x)c)d)') [snip] irb(main):007:0> class << parser irb(main):008:1> attr_reader :number_of_captures irb(main):009:1> end => nil irb(main):010:0> parser.number_of_captures => 2 irb(main):011:0> why have I never thought of this? -- Simon Strandgaard |
Re: Regexp Arity
On Wednesday 22 September 2004 02:54 pm, Yukihiro Matsumoto wrote:
> Hi, > > In message "Re: Regexp Arity" > > on Thu, 23 Sep 2004 03:26:44 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes: > |Just ran into a need to know how many parenthetical groupings a Regexp > | has. Would #arity for Regexp be a good idea? > > I'm not sure if it should be named 'arity'. Perhaps not, but I really can't think of a better word. Everything else seems long or odd sounding: #group_count #parentheticals_count #number_of_subexpressions Hmm... that brings up a good point. Would zero-width positive lookheads and/or non-backreferencing groups be counted? T. -- ( o _ カラチ // trans. / \ transami@runbox.com I don't give a damn for a man that can only spell a word one way. -Mark Twain |
Re: Regexp Arity
Hi --
On Thu, 23 Sep 2004, trans. (T. Onoma) wrote: > On Wednesday 22 September 2004 02:54 pm, Yukihiro Matsumoto wrote: > > Hi, > > > > In message "Re: Regexp Arity" > > > > on Thu, 23 Sep 2004 03:26:44 +0900, "trans. (T. Onoma)" > <transami@runbox.com> writes: > > |Just ran into a need to know how many parenthetical groupings a Regexp > > | has. Would #arity for Regexp be a good idea? > > > > I'm not sure if it should be named 'arity'. > > Perhaps not, but I really can't think of a better word. Everything else seems > long or odd sounding: > > #group_count > #parentheticals_count > #number_of_subexpressions > > Hmm... that brings up a good point. Would zero-width positive lookheads and/or > non-backreferencing groups be counted? To back up slightly: I can't help wondering under what conditions you would need to know this. Can you present the problem you were trying to solve? Maybe there's a simpler way. David -- David A. Black dblack@wobblini.net |
Re: Regexp Arity
On Wednesday 22 September 2004 21:47, David A. Black wrote:
> > <transami@runbox.com> writes: > > > |Just ran into a need to know how many parenthetical groupings a Regexp > > > | has. Would #arity for Regexp be a good idea? [snip] > > Hmm... that brings up a good point. Would zero-width positive lookheads > > and/or non-backreferencing groups be counted? > > To back up slightly: I can't help wondering under what conditions you > would need to know this. Can you present the problem you were trying > to solve? Maybe there's a simpler way. Maybe I should advertise some more for my regexp package irb(main):001:0> require 'regexp' => true irb(main):002:0> puts /this(feels(like)lisp|scheme)/.tree +-Sequence +-Inside set="t" +-Inside set="h" +-Inside set="i" +-Inside set="s" +-Group capture=1 +-Alternation +-Sequence | +-Inside set="f" | +-Inside set="e" | +-Inside set="e" | +-Inside set="l" | +-Inside set="s" | +-Group capture=2 | | +-Sequence | | +-Inside set="l" | | +-Inside set="i" | | +-Inside set="k" | | +-Inside set="e" | +-Inside set="l" | +-Inside set="i" | +-Inside set="s" | +-Inside set="p" +-Sequence +-Inside set="s" +-Inside set="c" +-Inside set="h" +-Inside set="e" +-Inside set="m" +-Inside set="e" => nil irb(main):003:0> to install just type rpa install re -- Simon Strandgaard |
Re: Regexp Arity
On Wednesday 22 September 2004 03:47 pm, David A. Black wrote:
> To back up slightly: I can't help wondering under what conditions you > would need to know this. Can you present the problem you were trying > to solve? Maybe there's a simpler way. I'm pattern matching a document. When a match is found the match/submatches are passed to various procs. If the regexp has groupings I want to pass the group matches, if not just the whole match. I could just go by the matchdata length, but the regexp is stored in a dedicated "token" class and that class may need to be initialized differently based on that "arity". But granted, I did just work out a different approach, so as of this moment I won't need it. Although I see no good reason that information shouldn't be available. As I think Simon pointed out with his engine, "it is in there". Thanks, T. |
Re: Regexp Arity
On Thursday, September 23, 2004, 4:56:23 AM, Austin wrote:
> On Thu, 23 Sep 2004 03:54:31 +0900, Yukihiro Matsumoto > <matz@ruby-lang.org> wrote: >> In message "Re: Regexp Arity" >> on Thu, 23 Sep 2004 03:26:44 +0900, "trans. (T. Onoma)" >> <transami@runbox.com> > |Just ran into a need to know how many >> parenthetical groupings a Regexp has. >> |Would #arity for Regexp be a good idea? >> I'm not sure if it should be named 'arity'. > Regexp#groups ? > Regexp#groupcount? Regexp#ngroups Gavin |
Re: Regexp Arity
* Gavin Sinclair <gsinclair@soyabean.com.au> [Sep 23, 2004 01:50]:
> > Regexp#groups ? > > Regexp#groupcount? > > Regexp#ngroups Best by far, so far, 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);} |
| All times are GMT. The time now is 07:46 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.