regular exp to extract dollar amount
I have a token in an extraction pattern that has alot of garbage in it, and I want to extract the first occurence of a number in the form
$xxx,xxx
OR
$x,xxx,xxx
OR
$xx,xxx,xxx
But I cant seem to get the regular expression function to work. Whats the right regular expression for this?
Well, with Regex, it's
Well, with Regex, it's usually good to be very specific for what you want to match, but in a case like dollar amounts, I'd just go with this:
\$\d[\d,]*
The "$" is a special character in regex, so you have to put the "\" before it.
This pattern will require that you have a $ followed by a digit. After that, any number of commas and digits may follow.
This won't match decimals on the end of the number, though. If you need the decimal, change it to this:
\$\d[\d,.]*
I find this easier than try to make some big pattern for one case, or another case, or another case, etc, etc.
Does this solve the problem?
Tim