E
Eyal Oren
Hi,
I am parsing query expressions, using a regular expression with
multiple matches in it, e.g. /(\w+)\w+)/.
I would like some code to execute on the first match (e.g.
constructing some object out of it) and some other code on the second
match (e.g. constructing some other object).
I can of course check the array of matches and find the non-nil
element, and decide which code to execute. But that becomes very
cumbersome with a large regex (with say 10 different matches).
So I would rather like to attach some code in a match directly, as one
does in parsing generators, e.g.
/(\w+:do_method)\w+:do_other_method)/.
Would something like that be possible in Ruby? I tried searching but
I'm not sure how such a feature would be called.
I am parsing query expressions, using a regular expression with
multiple matches in it, e.g. /(\w+)\w+)/.
I would like some code to execute on the first match (e.g.
constructing some object out of it) and some other code on the second
match (e.g. constructing some other object).
I can of course check the array of matches and find the non-nil
element, and decide which code to execute. But that becomes very
cumbersome with a large regex (with say 10 different matches).
So I would rather like to attach some code in a match directly, as one
does in parsing generators, e.g.
/(\w+:do_method)\w+:do_other_method)/.
Would something like that be possible in Ruby? I tried searching but
I'm not sure how such a feature would be called.