Generating regex to remove the beginning of a string


#1

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


#2

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.html#label-Anchors

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

http://ruby-doc.org/core-2.1.8/doc/regexp_rdoc.html#label-Character+Classes
http://ruby-doc.org/core-2.1.8/doc/regexp_rdoc.html#label-Repetition

input = “12mthenhdca_fld1414”
re = /\A\d+/
input =~ re
p $&


#3

thanks Onzo actually this regex /^\d+/ has worked out in matching the
beginning letters.