[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

reg exp question

(D. Alvarado)

1/25/2008 9:59:00 PM

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
2 Answers

7stud --

1/25/2008 10:33:00 PM

0

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
--
Posted via http://www.ruby-....

7stud --

1/25/2008 10:35:00 PM

0

7stud -- wrote:
>
> result = str.gsub(/\D/, "")
>

\D is the symbol for any character except a digit, which is shorthand
for [^0-9].
--
Posted via http://www.ruby-....