0

I am trying to write a regex in Java to detect a decimal or a integer from a given text.

I have used the following pattern.

Pattern.compile("(\\d*\\.*?\\d*)%");

My intention is match occurences like 5%,0.5%,.5%,5.0%.

Is my pattern sufficient for all the matches ?

user1965449
  • 2,849
  • 6
  • 34
  • 51
  • One good way to find out: write a good unit test/tests for it. :) – asteri Nov 14 '14 at 04:36
  • You pattern allows for more than one decimal point – Gary Nov 14 '14 at 04:36
  • 1
    This may help http://stackoverflow.com/questions/308122/simple-regular-expression-for-a-decimal-with-a-precision-of-2 http://stackoverflow.com/questions/5917082/regular-expression-to-match-numbers-with-or-without-commas-and-decimals-in-text – Sudhir kumar Nov 14 '14 at 04:36

0 Answers0