java - Check if String ends with two digits after a dot in Regular Expression? -


I am trying to test if a string is correct using a regular expression in Java after a point Ends with points. How can I get it?

Something like "500.23" should be true, while "50.3" or "50" should be returned false. I "500.00" .matches ("/ ^ [0-9] {2} $ /") but it does wrong.

Here is a regx that can help you:

  ^ \ D + \. \ D {2,2} $  

It can neither be perfect nor the most efficient, but you should move in the right direction.

^ says that the expression should start here
\ d any The number is shown for + , that the leading can appear as often as necessary (1-infinite)
.. means that you are expecting a point (.) At a point \ d {2,2} due to the trick From: It says that you want 2 and exactly 2 points (not less and more)
$ tells you to end that expression (later 2 points)

In Java, \ "if there is a need to avoid it will be:

  ^ \\ d * \\. \\ d {2} $  

Edit
If you do not need a digit before dot (. ) or if you Do not do the thing that comes before the dot, after that you can first convert \ d + to . in the answer to Bohemian (non surviving) Dot means that the expression can not contain any character (not only Digit), even then major ^ can no longer be necessary.

  \\. * \\. \\ d {2,2} $  

Comments