Robert thanks \A and \z is what I was looking for.
Can you explain though what that does though? I can not seem to find any
relevant information on it.
\A matches the beggining of the string and \z matches the end of the string.
If you don't "anchor" the regexp with those, what you match can match
anywhere within the string, even a substring. So for example:
irb(main):001:0> a = "abcdef"
=> "abcdef"
irb(main):005:0> a =~ /bc/
=> 1
This means that the regexp /bc/ has matched the string at position
one. Notice now if you anchor it that it doesn't match:
irb(main):006:0> a =~ /\Abc\z/
=> nil
irb(main):007:0> a =~ /\Aabcdef\z/
=> 0
www.rubular.com has a regular expression editor, where you can test,
and also a quick reference guide and a link to an online copy of the
pickaxe, although to be honest, not much is said about \A and \z
specifically.
You can also search here for more info about regexps:
http://www.regular-expressions.info/
Hope this helps,
Jesus.