From: Anthony Durity Date: 2006-02-07T02:01:29+09:00 Subject: Re: Merging regular expressions Yes! This can be done with alternation (which is what RegExp.union does) but I really really really want to know which sub-regexp matched - I can (maybe) sort out the derivative problem of conflicting sub-regexps when the time comes. So, think of the first requirement as wanting to know which sub-regexp in an array of regexps that have been unioned or alternated together triggers a match - the object is to save time iterating over an array of regexps. hmmm, Anthony (I think racc must implent this algorithm somewhere, I know not where) On 2/6/06, Robert Klemme wrote: > 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 > > >