From: Eero Saynatkari Date: 2006-02-07T04:29:09+09:00 Subject: Re: Merging regular expressions On 2006.02.07 04:26, Eero Saynatkari wrote: > On 2006.02.07 02:24, Anthony Durity wrote: > > Jacob, Brilliant! > > > > But... see my last post, i want to avoid iteration by merging all > > regexps into one large regexp. However, this is absolutely beautiful > > and correct. Taken with the replies I got earlier this is a great > > start. > > If at all possible, I would use Strings: > > re = ['foo', 'bar', 'baz', 'quux'] > regexp = re.map {|r| "(#{r})"}.join '|' > result = 'baz baa foo guggeli quux'.scan regexp Bah. result = 'baz baa foo guggeli quux'.scan /#{regexp}/ > p result > > You may need to tweak the regexp/builder a bit to > for example ensure there is whitespace on either > side or something. > > > > > Question... What would the following code output? > > > > r = [] > > r << /aaa/ > > r << /[ab][ab][ab]/ > > m = Regexp.union( *r ) > > m =~ "aaa" # => ? > > > > (I think I basically want to be able to twiddle with the finite > > automata the regexps make when they are compiled/created, I dunno if > > this is possible) > > > > Later, > > Anthony > > > > On 2/6/06, Jacob Fugal wrote: > > > On 2/6/06, Anthony Durity wrote: > > > > 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! > > > > > > > > > > > > Jacob Fugal E