Forum: Ruby Generating regex to remove the beginning of a string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
478deb011156847f3e4c9dbcc3899cfd?d=identicon&s=25 Sai Charan (charan90)
on 2017-02-08 16:03
Am required to delete the numbers in the beginning of the string.
"12mthenhdca_fld1414" is there any regex to match the numbers in the
beginning of the string.

Any help is highly appreciated.

Thanks,
Sai
150e3d60e1da33d0ef45a3fab66d6019?d=identicon&s=25 B. Onzo (bonzo_goat)
on 2017-02-08 16:36
Sai Charan wrote in post #1185544:
> Am required to delete the numbers in the beginning of the string.
> "12mthenhdca_fld1414" is there any regex to match the numbers in the
> beginning of the string.
>
> Any help is highly appreciated.
>
> Thanks,
> Sai

Yes, you can anchor a match to specific positions.

http://ruby-doc.org/core-2.1.8/doc/regexp_rdoc.htm...

You can match digit characters with the right character class and
quantifier.

http://ruby-doc.org/core-2.1.8/doc/regexp_rdoc.htm...
http://ruby-doc.org/core-2.1.8/doc/regexp_rdoc.htm...

input = "12mthenhdca_fld1414"
re = /\A\d+/
input =~ re
p $&
478deb011156847f3e4c9dbcc3899cfd?d=identicon&s=25 Sai Charan (charan90)
on 2017-02-08 16:51
thanks Onzo actually this regex /^\d+/  has worked out in matching the
beginning letters.
This topic is locked and can not be replied to.