你可以这样使用
regex:
if (str.matches("[-+]?[0-9]*\.?[0-9]+")) { // You can use the `\d` instead of `0-9` too! // Is a number - int, float, double }[-+]? -为标志。
[0-9] * 。?[0-9] + -用于数字和它们之间的小数点。
更新:-
如果也需要处理指数,则
regex可以使用以下内容。
String regex = "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?";



