import java.util.*;
import java.lang.*;
class Main
{
{
// your special characters
String regex
= "+ – && || ! ( ) { } [ ] ^ ” ~ * ? : \\"; // building a valid regex out of above
regex = '(' + regex.replaceAll("([^\\s]{1,2})(?=(?:\\s+|$))",
"\\\\Q$1\\\\E").replace(' ', '|') + ')';
// your string to be replaced
String str
= "content:you&&me"; // actual replacement
str = str.replaceAll(regex, "\\\\$1");
// printing the result
System.
out.
printf("********* replaced: [%s]%n", str
);
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CgpjbGFzcyBNYWluCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCSAgIC8vIHlvdXIgc3BlY2lhbCBjaGFyYWN0ZXJzCiAgICBTdHJpbmcgcmVnZXggPSAiKyDigJMgJiYgfHwgISAoICkgeyB9IFsgXSBeIOKAnSB+ICogPyA6IFxcIjsKICAgIC8vIGJ1aWxkaW5nIGEgdmFsaWQgcmVnZXggb3V0IG9mIGFib3ZlCiAgICByZWdleCA9ICcoJyArIHJlZ2V4LnJlcGxhY2VBbGwoIihbXlxcc117MSwyfSkoPz0oPzpcXHMrfCQpKSIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIlxcXFxRJDFcXFxcRSIpLnJlcGxhY2UoJyAnLCAnfCcpICsgJyknOwoKICAgIC8vIHlvdXIgc3RyaW5nIHRvIGJlIHJlcGxhY2VkCiAgICBTdHJpbmcgc3RyID0gImNvbnRlbnQ6eW91JiZtZSI7CiAgICAvLyBhY3R1YWwgcmVwbGFjZW1lbnQKICAgIHN0ciA9IHN0ci5yZXBsYWNlQWxsKHJlZ2V4LCAiXFxcXCQxIik7CgogICAgLy8gcHJpbnRpbmcgdGhlIHJlc3VsdAogICAgU3lzdGVtLm91dC5wcmludGYoIioqKioqKioqKiByZXBsYWNlZDogWyVzXSVuIiwgc3RyKTsKCgl9Cn0=