Hi,
If I have a variable @fax, how can I apply a regular expression to the
variable such that all non-numeric characters are removed? You can
assume the fax number is of a valid US format.
Thanks, - Dave
Hi,
If I have a variable @fax, how can I apply a regular expression to the
variable such that all non-numeric characters are removed? You can
assume the fax number is of a valid US format.
Thanks, - Dave
laredotornado wrote:
If I have a variable @fax, how can I apply a regular expression to the
variable such that all non-numeric characters are removed? You can
assume the fax number is of a valid US format.
str = ‘1234abc5d6e7f8ghi’
result = str.gsub(/\D/, “”)
puts result
–output:–
12345678
7stud – wrote:
result = str.gsub(/\D/, “”)
\D is the symbol for any character except a digit, which is shorthand
for [^0-9].
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs