'Optional characters in Flex expression



I'm trying to make a flex expression which identifies money, to 2 decimal places. This isn't for any practical use, I'm just messing around with flex and trying to learn it.

I am looking for money in this format: $100.00 or $100000.00 or -$100.00

This is not much of an issue, I can use this expression:
[$][0-9]+[.][0-9]+

I can also add to it to detect negative numbers:
-?[$][0-9]+[.][0-9]+

My problem is, with how I have it $100.00 would be identified as expected, but $100.000000 would also be identified as a money token. How do I ensure that there are only 2 decimals shown?

Is there any way to tell Flex to limit the amount of characters in an expression? I could do something like this;
-?[$][0-9]+[.][0-9][0-9]

but this seems like a bad solution. What if I wanted 10 decimal places? Tagging lots of [0-9]'s on the end seems like a bad idea.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source