在下面的行中,如果我们有单引号(')那么我们必须用'||'''替换它,但如果我们有两次单引号('')那么它应该是原样.
我尝试下面的一段代码没有给我正确的输出.
代码片段:
static String replaceSingleQuoteOnly = "('(?!')'{0})";
String line2 = "Your Form xyz doesn't show the same child''s name as the name in your account with us.";
System.out.println(line2.replaceAll(replaceSingleQuoteOnly, "'||'''"));
Run Code Online (Sandbox Code Playgroud)
上述代码的实际输出:
Your Form xyz doesn'||'''t show the same child''||'''s name as the name in your account with us.
Run Code Online (Sandbox Code Playgroud)
预期结果:
Your Form xyz doesn'||'''t show the same child''s name as the name in your account with us.
Run Code Online (Sandbox Code Playgroud)
正则表达式替换子"是与孩子""||"'的.孩子 应该保持原样.
员工Bean类:
public class Employee2 {
private String id;
private String name;
private String designation;
private double salary;
private double totalExperience;
// private Address2 address2;
private Collection<Technology2> technologies2;
private String content_type = "employee2";
public Employee2() {
super();
}
public Employee2(String id, String name, String designation, double salary, double totalExperience,
Collection<Technology2> technologies2) {
super();
this.id = id;
this.name = name;
this.designation = designation;
this.salary = salary;
this.totalExperience = totalExperience;
// this.address2 = address2;
this.technologies2 = technologies2;
}
/**
* @return the id …Run Code Online (Sandbox Code Playgroud)