Hi,
str = "v38"
I want to check in string using regular expression that 1st character is
albhabet and rest following is number. As i new to regular expression,
please help me.
Thanks
Saurabh
···
--
Posted via http://www.ruby-forum.com/.
Hi,
str = "v38"
I want to check in string using regular expression that 1st character is
albhabet and rest following is number. As i new to regular expression,
please help me.
Thanks
Saurabh
--
Posted via http://www.ruby-forum.com/.
Try using rubular.com to verify your regular expression. This a great tool to help with developing regular expressions.
From my iPhone
---
Pat
On Sep 22, 2011, at 6:35 AM, "Saurabh A." <getsauin@gmail.com> wrote:
Is this right.
str.match(/(\w)(\d+)(\d+)/)
--
Posted via http://www.ruby-forum.com/\.
Using Rubular is a good way of quickly checking regular expressions:
Note that \d+\d+ is almost redundant, but you'll actually not match "v3".
On Thu, Sep 22, 2011 at 2:35 PM, Saurabh A. <getsauin@gmail.com> wrote:
Is this right.
str.match(/(\w)(\d+)(\d+)/)
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
On Thu, Sep 22, 2011 at 3:43 PM, Adam Prescott <adam@aprescott.com> wrote:
On Thu, Sep 22, 2011 at 2:35 PM, Saurabh A. <getsauin@gmail.com> wrote:
Is this right.
str.match(/(\w)(\d+)(\d+)/)
Using Rubular is a good way of quickly checking regular expressions:
Rubular: (\w)(\d+)(\d+)Note that \d+\d+ is almost redundant, but you'll actually not match "v3".
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/