包括5种形式,如测试结果
import java.util.Scanner; import java.util.regex.*; public class Com { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str=sc.nextLine(); Pattern p = Pattern.compile("\\d+||\\d*\\.\\d+||\\d*\\.?\\d+?e[+-]\\d*\\.?\\d+?||e[+-]\\d*\\.?\\d+?"); Matcher m = p.matcher(str); boolean b = m.matches(); System.out.println(b); } } }
34
true
2.34
true
.56
true
3e+45
true
3e-0.5
true
3e45
false
原文:http://www.cnblogs.com/xuhuaiqu/p/4458552.html