关于数字字符串的正则表达式问题,有点难度 我有一串数字,数字的前置和后置都可能为0,要求实现下面的2个正则表达式1. 前置例如: 0010 --》 10,0000--》""2. 后置例如: 0010 --》 001- ,1200--》12--, 0000--》----在线等答复.... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试看//前置 "^[0]+([^0]?)System.out.println("0010".replaceAll("^[0]+([^0]?)", "$1"));System.out.println("0000".replaceAll("^[0]+([^0]?)", "$1"));//后置 "([^0]?)[0]+$"System.out.println("0010".replaceAll("([^0]?)[0]+$", "$1"));System.out.println("1200".replaceAll("([^0]?)[0]+$", "$1"));System.out.println("0000".replaceAll("([^0]?)[0]+$", "$1")); System.out.println("000123123000".replaceAll("(?:^0*)|(?:0*$)", "")); 前后0是否相等?String str = "00010234000";Pattern p = Pattern.compile("(^0*)(\\d*)(\\1)");Matcher m = p.matcher(str);while(m.find()){ System.out.println(m.group(2)+(m.group(3)).replaceAll("0","-"));} 有关eclipse jdk jre 配置问题 初学者困惑 小问题! SWT中GridData的问题 不能调用ArrayList.indexOf方法 我想学Collection,大家知道有什么连接地址吗? 'Launching Base64'错误如何解决 Socket的测试程序,本地echo端口怎么连接不上呢? 初学者的问题:xml的文件数据读取问题。谢谢! 这样获得web server 的IP地址? 要使用core java需要在My Eclipse中导入哪些东西 Mysql安装之后不能用是怎么回事?
//前置 "^[0]+([^0]?)
System.out.println("0010".replaceAll("^[0]+([^0]?)", "$1"));
System.out.println("0000".replaceAll("^[0]+([^0]?)", "$1"));
//后置 "([^0]?)[0]+$"
System.out.println("0010".replaceAll("([^0]?)[0]+$", "$1"));
System.out.println("1200".replaceAll("([^0]?)[0]+$", "$1"));
System.out.println("0000".replaceAll("([^0]?)[0]+$", "$1"));
Pattern p = Pattern.compile("(^0*)(\\d*)(\\1)");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group(2)+(m.group(3)).replaceAll("0","-"));
}