From: Robert Klemme Date: 2004-10-22T17:19:14+09:00 Subject: Re: A little help on finding the closest match "trans. (T. Onoma)" schrieb im Newsbeitrag news:200410212302.34298.transami@runbox.com... > On Thursday 21 October 2004 10:49 pm, trans. (T. Onoma) wrote: > | On Thursday 21 October 2004 10:21 pm, nobu.nokada@softhome.net wrote: > | | Hi, > | | > | | At Fri, 22 Oct 2004 10:38:24 +0900, > | | > | | trans. (T. Onoma) wrote in [ruby-talk:117331]: > | | > # example data > | | > str = "some string abc xyz" > | | > tokens = [ /abc/, /xyz/ ] > | | > | | str.index(/#{tokens.join("|")}/) > > Actually, I'm still playing with it, but it looks like this won't work b/c I > have subexpressions in my actual tokens. e.g. > > [ /()(abc)(\S)/, ... ] If you're just interested in the tokens you probably want this: /(token1)|(token2(?:sub2))/ i.e. use capturing groups for tokens and non capturing groups for all sub groups. > And the match indexes seem to get lost when I join them. Also, I'm not sure > how to tell which token it was that actually matched. You can use Regexp#match. Or use scan in a method with return in the block. robert