Suppose I have arbitrary text with a currency value in it, like this:
The price today is $1,234.56! Don't miss out!
I want to extract the number of cents as an int, ie:
123456
Some criteria:
- The 000’s comma is optional
- The price is less than $1,000,000.00
- The
$is always there - The decimal part is always there
I have tried using Pattern and Matcher, but it seems all too messy.
What is the simplest code that will do this?
I think this single line, which includes the parse to int, is about as terse as it can be: