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
Solved

How do I eliminate characters in a string?

Posted on 1998-07-24
6
133 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse log and delete the file 17 176
Perl Scripting from a shell script with if and for 4 87
perl getopt long help 34 70
Control Number of Log Files -Perl 7 86
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 …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

766 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