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: Intermediate:
Regex capture for numbers with a comma

 



suprdavc
New User

Mar 14, 2009, 3:17 PM

Post #1 of 2 (739 views)
Regex capture for numbers with a comma Can't Post

I want to capture a number (price) from each line of a file (credit card statement). The number may or may not have 1 comma.

I was using /([0-9]{1,3}\.[0-9]{1,2})/; which was working great for numbers like:

102.34
1.54
21.21

I forgot about numbers with a comma, like 1,342.54. I tried this, but it only returns the first number:

/([0-9]*,?[0-9]{1,3}\.[0-9]{1,2})/;

Need some help here


suprdavc
New User

Mar 14, 2009, 9:29 PM

Post #2 of 2 (664 views)
Re: [suprdavc] Regex capture for numbers with a comma [In reply to] Can't Post

Ok, I figured it out: /(\d*?,*?\d{1,3}\.\d{1,2})/;


(This post was edited by suprdavc on Mar 14, 2009, 9:29 PM)

 
 


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

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