java基础之正则

*、匹配以'-'开头以'.'结尾且结果可能出现多次的情况

	public static void main(String[] argv) {
		//匹配以'-'开头以'.'结尾且结果可能出现多次的情况
		Pattern p = Pattern.compile("-[^\\.]*\\.");
		String s = "JL20160108-W150002.xlsJL20160108-W150002.xlsJL20160108-W150002.xls";
		Matcher m = p.matcher(s);
		while (m.find()) {
			//查询匹配的字符串,
			String ss = m.group().replace("-", "").replace(".", "");
			System.out.println("替换前:"+m.group()+"---替换后:"+ss);
		}
	}

猜你喜欢

转载自lbovinl.iteye.com/blog/2333912