See this java code: -
s = s.replaceAll( "\\\\", "\\\\\\\\" ).replaceAll( "\\$", "\\\\\\$" );
I donโt seem to understand this. This regular expression replaces everything.
I tried the following C # code ...
text = text.RegexReplace("\\\\", "\\\\\\\\"); text = text.RegexReplace("\\$", "\\\\\\$");
But if I have the following unit test: -
} ul[id$=foo] label:hover {
The java code returns: } ul[id\$=foo] label:hover {
My C # code returns: } ul[id\\\$=foo] label:hover {
So, I'm not sure I understand why my C # code puts more \ in, mainly regarding the representation of these control characters .. ??
Update:
So, when I use the idea of โโXXX only using text.Replace(..) , this works. eg.
text = text.Replace("\\\\", "\\\\\\\\"); text = text.Replace("\\$", "\\\\\\$");
But I was hoping to stick with RegEx ... to try to keep it as close to the java code as possible.
Extension Method Used ...
public static string RegexReplace(this string input, string pattern, string replacement) { return Regex.Replace(input, pattern, replacement); }
hmm ...