• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

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?
0
tmbb
Asked:
tmbb
1 Solution
 
ozoCommented:
($after = $before) =~ tr/0-9//cd;
0
 
n0thingCommented:
or $before =~ s/\D//g;
will remove anything not a digit in $before.
0
 
tmbbAuthor Commented:
Both work great!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ozoCommented:
which do you want to grade?
0
 
TSchockCommented:
$_ =~ s/\D//g;
will remove anything excepts digits
0
 
b2piCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now