Solved

How do I eliminate characters in a string?

Posted on 1998-07-24
6
129 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
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now