From: yermej Date: 2007-11-22T08:54:59+09:00 Subject: Re: help with regex On Nov 21, 5:46 pm, Junkone wrote: > i have this string > a="USD.CHF.ABC" > irb(main):024:0> a.match(/^USD/) > => # > irb(main):025:0> $1 > => nil > > i want to use regex to see if it matches USD as first 3 characters and > here is my attmept. I am not sure why there is no match, any help is > appreciated. You can either assign the MatchData that match returns to a variable: > m = a.match /^USD/ > m[0] or you can use parens in your regex to capture the match into $1: > a.match /^(USD)/ > $1