Regular Expressions
I'm writing a linux script for class, and am running into trouble with some of the logic of the regular expressions here...
I have the date done (it has to follow a mm/dd/yyyy format, so I know exactly how many numbers are needed) but now I need one for currency that needs to follow the $2943.00 format (always 2 decimals, always $ in front, commas optional, anything else is a no match)
The problem is, there could technically be an infinite number of numbers there. As long as they're preceded by a $ and ended with a . and cents, its ok
I'm not sure exactly how to allow any number of digits, and it's probably something really simple that I just don't see <!--emo&:(--><img src='http://www.unknownworlds.com/forums/html//emoticons/sad-fix.gif' border='0' style='vertical-align:middle' alt='sad-fix.gif' /><!--endemo-->
Here's a few examples...
$1,000.00 Match
$1000.00 Match
$50.24 Match
4,000.10 No match (no $)
$800 No Match (no cents)
I have the date done (it has to follow a mm/dd/yyyy format, so I know exactly how many numbers are needed) but now I need one for currency that needs to follow the $2943.00 format (always 2 decimals, always $ in front, commas optional, anything else is a no match)
The problem is, there could technically be an infinite number of numbers there. As long as they're preceded by a $ and ended with a . and cents, its ok
I'm not sure exactly how to allow any number of digits, and it's probably something really simple that I just don't see <!--emo&:(--><img src='http://www.unknownworlds.com/forums/html//emoticons/sad-fix.gif' border='0' style='vertical-align:middle' alt='sad-fix.gif' /><!--endemo-->
Here's a few examples...
$1,000.00 Match
$1000.00 Match
$50.24 Match
4,000.10 No match (no $)
$800 No Match (no cents)
Comments
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->^[$]([0-9]+[.][0-9]{2})$<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
The + means one or more of the previous character set. This might be slightly off, but should be the general idea you're looking for.
Ah thats exactly what I was having trouble with
Thanks a bunch!
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->^[$]([0-9]+[.][0-9]{2})$<!--c2--></td></tr></table><div class='postcolor'><!--ec2--><!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
What about commas, though?
You know, the ones that separate groups of three digits, as in:
$1,000,000.00
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->^[$]([0-9]+[.][0-9]{2})$<!--c2--></td></tr></table><div class='postcolor'><!--ec2--><!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
What about commas, though?
You know, the ones that separate groups of three digits, as in:
$1,000,000.00 <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
this might work:
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->^[$](([0-9]+,*)+[.][0-9]{2})$<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->^[$]([0-9]+[.][0-9]{2})$<!--c2--></td></tr></table><div class='postcolor'><!--ec2--><!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
What about commas, though?
You know, the ones that separate groups of three digits, as in:
$1,000,000.00 <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->^(\$([0-9]{1,3}\,)([0-9]{3}\,)*[0-9]{3}[.][0-9]{2})|(\$[0-9]+[.][0-9]{2})$<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
That one should work with commas too <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html//emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
The first group can have 1-3 digits then a comma, then all subsequent groups have to have 3 digits then a comma and the last group has 3 digits then a period, then 2 digits. The second case is if the entire thing is any number of digits, with a period and 2 digits at the end. Oh, and a dollar sign at the front.
Edit: Skulkbait, that new one you have also accepts stuff like "$1,0000,,,,,0.00" (I just ran it through a testing thing)