From: Jeff Wood Date: 2005-11-26T22:23:06+09:00 Subject: Re: What branch of (|) RE is match? ------=_Part_10454_13750018.1133011379378 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If you put each of the variants into seperate groups, you can check nil on groups and will know exactly which matched. a =3D "hello world" b =3D /(ell)|(goo)/ c =3D b.match a c.to_a # first element is match, second the match on the group (ell), third the match on (goo) should be what you're after. j. On 11/26/05, S.Z. wrote: > > I have a fragment like this: > > variant=3D [ /[abc]/, /[123]/, /[xyz]/ ]; > re=3D /aaa\s(#{variant.join('|')})\sbbb/; > mch=3D re.match($stdin.read); > > (Remove the semicolons if you hate them.) > > Now, I need to know what branch of variant is match, /[abc]/ or /[123]/ > or /[xyz]/ > How can I reveal it? > > variant can be iterated with mch[1] : > > vm=3D variant.find { |v| v.match(mch[1]); } > > But it is superfluous work, isn't it? > > > -- "Remember. Understand. Believe. Yield! -> http://ruby-lang.org" Jeff Wood ------=_Part_10454_13750018.1133011379378--