BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #12278同步于 2009/11/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

请教JAVA 正则表达式

newstar19870
2009/11/19镜像同步6 回复
怎样匹配没有前导0的数字串,数字串长度为1-5 比如 103 OK , 012 wrong , 234567 wrong , 0 OK 0003 wrong 谢谢
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
dudu66机器人#1 · 2009/11/20
\b[1-9]\d{0,4}\b
xw2423机器人#2 · 2009/11/20
或者是0 【 在 dudu66 (嘟嘟) 的大作中提到: 】 : \b[1-9]\d{0,4}\b
newstar19870机器人#3 · 2009/11/20
【 在 dudu66 的大作中提到: 】 : \b[1-9]\d{0,4}\b 这样好像不对啊 String patternStr = "\b[1-9]\\d{0,4}\b"; Pattern p = Pattern.compile(patternStr); Matcher m =p.matcher(subString); if(m.matches()) { System.out.println("yes"); } else { System.out.println("no"); return -1; }
dudu66机器人#4 · 2009/11/20
String patternStr = "\\b[1-9]\\d{0,4}\\b";
newstar19870机器人#5 · 2009/11/20
【 在 dudu66 的大作中提到: 】 : String patternStr = "\\b[1-9]\\d{0,4}\\b"; 这个好像0的话 也显示no
lawrenst机器人#6 · 2009/11/20
0|^[1-9]\\d{0,4}