Gossamer Forum
Home : General : Perl Programming :

How to get only the digits out of $input

Quote Reply
How to get only the digits out of $input
When $input = "D-47462";

How do I make $input into "47462" ?

Normally I would use:
$input =~ s/A//gi;
$input =~ s/B//gi;
$input =~ s/C//gi;
But It should be much easier! (I Hope...)
Quote Reply
Re: How to get only the digits out of $input In reply to
Just want to say you can't rely on the users so therefore this code:

$inpit =~ s/(\D+)//g;

I hope it works, i did not tested it!

[This message has been edited by chrishintz (edited April 19, 1999).]
Quote Reply
Re: How to get only the digits out of $input In reply to
If the format of $input is always going to be the same (a letter, followed by a dash, followed by the 5 digit number), you could use:

$input = "D-47462";
$input = substr($input,2,5);

--mark
Quote Reply
Re: How to get only the digits out of $input In reply to
Yes that would work too, and would be a method to use if the value of input does NOT always meet the same format (I suppose I should have mentioned that before)

Smile

--mark