T
trans. (T. Onoma)
Just ran into a need to know how many parenthetical groupings a Regexp has.
Would #arity for Regexp be a good idea?
T.
Would #arity for Regexp be a good idea?
T.
In message "Re: Regexp Arity"
on Thu, 23 Sep 2004 03:26:44 +0900, "trans. (T. Onoma)" <[email protected]> > |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'.
Just ran into a need to know how many parenthetical groupings a Regexp has.
Would #arity for Regexp be a good idea?
Hi,
In message "Re: Regexp Arity"
|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.
/ \ (e-mail address removed)
I don't give a damn for a man that can only spell a word one way.
-Mark Twain
Hi,
In message "Re: Regexp 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
[snip]|Just ran into a need to know how many parenthetical groupings a Regexp
| has. Would #arity for Regexp be a good idea?
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.
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.
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?
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.
Which groups are counted here? There are capturing groups and
non-capturing groups. Or is this the sum of those two numbers?
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.
I agree. It's sounding like this is being informally proposed as a
new core method (rather than just discussed as something one might
write ad hoc), and I haven't seen a case being made for it at all.
You can query whether the regexp at hand ignores case or not. (That's thetrans. (T. Onoma) said:BTW --What's the use case of #casefold?
T.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.