On Thu, 2004-05-20 at 21:22, Rich Fernandez wrote:
> I'm unclear about how alternation works in a regex.
>
> Say I want to find either "foo" or "bar" within a string. I don't care which
> one I match, only that I make a match.
> Would this be correct: /foo|bar/
>
> Should they be grouped thusl
> Would this be correct: /foo|bar/
Yes.
> Should they be grouped thusly: /(foo|bar)/
This works too, but has the side effect of setting $1 to the matched value,
either "foo" or "bar".
> What about /(?:foo|bar)/ ?
This is ok too, but the parens aren't necessary. If you wanted to search
for