这将处理整数和小数:-
private Pattern p = Pattern.compile("\d+(\.\d+)?");@Testpublic void testInteger() { Matcher m =p.matcher("10"); assertTrue(m.find()); assertEquals("10", m.group());}@Testpublic void testDecimal() { Matcher m =p.matcher("10.99"); assertTrue(m.find()); assertEquals("10.99", m.group());}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)