CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
A simplier way to write this regex ?

 



marco
Novice

Mar 21, 2004, 7:49 AM

Post #1 of 4 (706 views)
A simplier way to write this regex ? Can't Post

I need to take out all the non alpha-numeric caracters exept the "."

I.E.: From $158.00 CAD I need to get: 158.00



Here is how I do it:

$string =~ s/[A-Z]//;
$string =~ s/\$//;
print "$string\n";


It works, but I am sure there is a simplier way. I have tried many combinations but it didn't work.
Anybody knows ?

Marco


davorg
Thaumaturge / Moderator

Mar 21, 2004, 1:01 PM

Post #2 of 4 (703 views)
Re: [marco] A simplier way to write this regex ? [In reply to] Can't Post

Your description doesn't match what your code does. You say that you want to remove "non alpha-numeric" characters, but you remove "CAD" - all of which _are_ alpha-numeric characters.

So what do you actually want to do?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


marco
Novice

Mar 21, 2004, 2:01 PM

Post #3 of 4 (702 views)
Re: [davorg] A simplier way to write this regex ? [In reply to] Can't Post


In Reply To
Your description doesn't match what your code does. You say that you want to remove "non alpha-numeric" characters, but you remove "CAD" - all of which _are_ alpha-numeric characters.

So what do you actually want to do?





Then my english is worst than I thought. Crazy

I want to do as my example state:

I.E.: From $158.00 CAD I need to get: 158.00


Marco


(This post was edited by marco on Mar 21, 2004, 2:01 PM)


davorg
Thaumaturge / Moderator

Mar 21, 2004, 2:29 PM

Post #4 of 4 (700 views)
Re: [marco] A simplier way to write this regex ? [In reply to] Can't Post

Try this:

Code
$string =~ s/(\d+\.\d+)/$1/;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives