Reg exp question

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].