From: Robert Klemme Date: 2006-02-07T01:43:20+09:00 Subject: Re: Merging regular expressions Anthony Durity wrote: > Thanks Robert, thanks Dave, > > I see what ye both mean. I was more thinking along the lines of a > situation like this. To avoid iterating over the array, I would like > to compress the regexps into a large regexp while still preserving the > identity of each regexp within the meta-regexp, something akin to what > happens when the scanner of a lexer is created. > So, imagine this trivial situation... > > r[0] = /a/ > r[1] = /b/ > m = Regexp.union(r0.source, r1.source) > # _but_ when I go to check s with > m =~ s > # if it matches, i want it to tell me which of the original r[i] would > have matched! Didn't you originally state that you wanted to ensure that not two regexps match at the same time? I mean this is something different. What you now state can be done with an alternation - but you'll only see one of your sub regexps match, i.e. /(foo)|(bar)/. > See what I mean? Will I hack the Ruby source? Can this be done in > Ruby? Will I have to do it in C? The first question is: can this be done with regexps? First of all I'd like to hear the exact requirements before we go on with this. I have the feeling that they are not clear yet - or at least that they have not become clear to me. Cheers robert