-5

I have to write a regular expression pattern in java for numbers in the range -100.00 to 9999.99 . The allowable number of decimal places is exactly 2. Please help me.

  • 1
    http://stackoverflow.com/tags/regex/info <-- read the tag wiki of the tag you used. – Tunaki Apr 25 '16 at 11:23
  • 2
    JavaScript <> Java – Filburt Apr 25 '16 at 11:27
  • As the answers have been closed: I would use something like this: `^((-[\d]{0,2}\.[\d]{2}|-100.00)|([\d]{0,4}\.[\d]{2}))` This will match `-0.00` to `-100.00` and `0.00` to `9999.99` For the example, see [here](https://regex101.com/r/mN6uT5/2) – KyleFairns Apr 25 '16 at 11:43

2 Answers2

1

If I understood your question correctly, you are asking for the range from -100.00 to +9999.99. Hence the correct answer would be:

(?<!\d)(-\d\d?|-100|(?<!-)\d{1,4})\.\d{2}(?!\d)

Checking on both sides to validate that you aren't getting part of a number.

0

-\d{3,4}\.\d{2}

Explanation:
- - match the minus
\d{3,4} - match three or four digits
\. - match fullstop
\d{2} - match two digits

Vampire
  • 35,631
  • 4
  • 76
  • 102