Solved

How do I eliminate characters in a string?

Posted on 1998-07-24
6
138 Views
Last Modified: 2010-03-05
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
Comment
Question by:tmbb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1208746
($after = $before) =~ tr/0-9//cd;
0
 
LVL 5

Expert Comment

by:n0thing
ID: 1208747
or $before =~ s/\D//g;
will remove anything not a digit in $before.
0
 

Author Comment

by:tmbb
ID: 1208748
Both work great!
0
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!

 
LVL 84

Expert Comment

by:ozo
ID: 1208749
which do you want to grade?
0
 
LVL 1

Accepted Solution

by:
TSchock earned 200 total points
ID: 1208750
$_ =~ s/\D//g;
will remove anything excepts digits
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208751
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question