62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test{
public static void main(String[] args){
String content = "学生姓名='张三' or 学生姓名='学生姓名' or 学生姓名='学生姓名sadasd'";
process(content);
}
private static void process(String content){
String withoutQuotation = content.replaceAll("'","");
if((content.length() - withoutQuotation.length()) % 2 != 0){
System.out.printf("'%s' is invalid!\n",content);
throw new RuntimeException("invalid content");
}
String regex = "学生姓名(?=([^']*?'[^']*'[^']*)*$)";
String result = content.replaceAll(regex,"stuName");
System.out.println(result);
}
}
result:
---------- java ----------
stuName='张三' or stuName='学生姓名' or stuName='学生姓名sadasd'
Output completed (0 sec consumed) - Normal Termination