Junkone <junkone1 / gmail.com> writes:

> i have this string
> a="USD.CHF.ABC"
> irb(main):024:0> a.match(/^USD/)
> => #<MatchData:0x2e6be30>
> 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.

Actually, there was a match and a MatchData object was returned (which
you silently ignored).

Maybe this example will help:
IRB-> match_data = "USD.CHF.ABC".match(/^USD/)
=> #<MatchData:0x578744>
IRB-> match_data.to_a
=> ["USD"]
IRB-> match_data = "CHF.ABC.USD".match(/^USD/)
=> nil

Hope that helps.