正则表达式进行字符串替换!将奇数和偶数的字符串替换成不同的!并且忽略大小写查找

	Pattern p = Pattern.compile("java", Pattern.CASE_INSENSITIVE);
		Matcher m = p.matcher("java Java JaVa IloveJAVA you hate jaVAadsladl");
		StringBuffer buf = new StringBuffer();
		int i = 0;
		while(m.find()) {
			i++;
			if(i %2 == 0){
				m.appendReplacement(buf, "java");
			} else {
				m.appendReplacement(buf, "JAVA");
			}
		}
		p(buf);
		
		



你可能感兴趣的:(java,正则表达式)