Link to home
Start Free TrialLog in
Avatar of tmbb
tmbb

asked on

How do I eliminate characters in a string?

I have a scalar that is in the form of mixed numbers, characters, and symbols.  I want to process this scalar so that I end up with only the number part.  

Here's an example of what I want to happen.

$before = '12-3 abc 90 def'
$after = '12390'

Any hints on how to do this?
Avatar of ozo
ozo
Flag of United States of America image

($after = $before) =~ tr/0-9//cd;
or $before =~ s/\D//g;
will remove anything not a digit in $before.
Avatar of tmbb
tmbb

ASKER

Both work great!
which do you want to grade?
ASKER CERTIFIED SOLUTION
Avatar of TSchock
TSchock

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tmbb;

Please reject TSchock's answer, and ask either ozo or n0thing to submit a question (You can even split points by posting a 0-point question to the customer service area).

TSchock's answer is either an inadvertent mistake, or a blatant attempt to take someone else's points by hoping that you don't notice that he slipped an answer in there, and get the points from auto-grading