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-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
reg exp question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password