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

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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.