From: Robert Klemme Date: 2011-09-22T22:56:06+09:00 Subject: Re: RegEx Help For checking alphnumeric On Thu, Sep 22, 2011 at 3:43 PM, Adam Prescott wrote: > On Thu, Sep 22, 2011 at 2:35 PM, Saurabh A. wrote: > >> Is this right. >> >> str.match(/(\w)(\d+)(\d+)/) > > > Using Rubular is a good way of quickly checking regular expressions: > http://rubular.com/r/0VTmjIcQ7j > > Note that \d+\d+ is almost redundant, but you'll actually not match "v3". Folks, you forgot anchoring and also that \w matches more than just characters: irb(main):006:0> /\w+\d+/ =~ '++++_0344' => 4 irb(main):007:0> /\w+\d+/ =~ '_1' => 0 So better match (!) for the criterion given is /\A[a-z]\d+\z/i =~ s /\A\p{Alpha}\d+\z/ =~ s # on 1.9 and on Saurabh, I recommend the book "Mastering Regular Expressions". There are also quite a few tutorials on the web. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/