Generating regex to remove the beginning of a string

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

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 $&

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs