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.
6a600edc260e7d9468a04c13f865083d?d=identicon&s=25 Sai C. (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
27ea9408dab07b5a394c45f07ca50fd8?d=identicon&s=25 B. O. (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 $&
6a600edc260e7d9468a04c13f865083d?d=identicon&s=25 Sai C. (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.