正则表达式提取双引号之间的内容,当然了可以找到就可以实现替换了。
String str="this is \"Tom\" and \"Eric\", this is \"Bruce lee\", he is a chinese, name is \"李小龙\"。"; Pattern p=Pattern.compile("\"(.*?)\""); Matcher m=p.matcher(str); int i=0; while(m.find()) { str=str.replace(m.group(),""+(i++)); } System.out.println(str);