On 2/6/06, Anthony Durity <anthony.durity / gmail.com> wrote:
> 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.

<snip>

> (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)

Ah. Well in that case, I don't think you're gonna be able to play in
pure-ruby-land, since you'll need access to the regex engine itself.
You might be able to do it with a combination of one regex for
alternation ("do any match") and another for exclusion ("does just one
match"), but at that point you'll probably be negating any speed
savings over the iteration (I assume that's what you're after).

> Question... What would the following code output?
>
> r = []
> r << /aaa/
> r << /[ab][ab][ab]/
> m = Regexp.union( *r )
> m =~ "aaa" #  => ?

That should raise the "ambiguous input" exception, since both /aaa/ =~
"aaa" and /[ab][ab][ab]/ =~ "aaa" are true.

Jacob Fugal