jeudi 1 juin 2017

I want Java Pattern.compile to recognize positive or negative integers or decimals

In Java I want to use Pattern.compile(String regexp) to find a negative or positive integer or decimal.

Ex. (1) (11) (1.1) (11.11) (-1) (-11) (-1.1) (-11.11)

I have found several answers online that tell me this is the correct regexp, but it ignores "-" sign ever single time.

Pattern pattern1 = Pattern.compile("(\\-?\\d+(\\.\\d+)?)");

Aucun commentaire:

Enregistrer un commentaire