javaregex

Regex to find a float


I've never used regex before, but this java function requires it (shown here: How to set Edittext view allow only two numeric values and two decimal values like ##.##)

I basically just need to get a float from it the text box, should be simple. I used a tool and it said this should work:

String re1="([+-]?\\d*\\.\\d+)(?![-+0-9\\.])";

But it doesn't seem to be working, it doesn't let me put anything in the text box.

What's the right way to do this? Thanks


Solution

  • Try this:

    String re1="^([+-]?\\d*\\.?\\d*)$";