In the line below, if we have a single quote ('), we should replace it with "||", but if we have a single quote twice (' '), then it should be as it is.
I tried below a piece of code that does not give me the correct output.
Code snippet:
static String replaceSingleQuoteOnly = "('(?!')'{0})"; String line2 = "Your Form xyz doesn't show the same child' name as the name in your account with us."; System.out.println(line2.replaceAll(replaceSingleQuoteOnly, "'||'''"));
Actual output from the code above:
Your Form xyz doesn'||'''t show the same child''||'' name as the name in your account with us.
Expected Result:
Your Form xyz doesn'||'''t show the same child' name as the name in your account with us.
The regular expression replaces child ' with child' '||' '' s . the child's must remain as he is.
source share