chuck
                                
                                
                                
                                    chuck copied to clipboard
                            
                            
                            
                        Weird regex replacement behaviour
"\"\"" => string x;
<<< x >>>;
<<< RegEx.replaceAll("\"", "\\\"", x) >>>;
// expected it to print "\"\"", got "\""" instead
"\"f\"" => string y;
<<< y >>>;
<<< RegEx.replaceAll("\"", "\\\"", y) >>>;
// this on the other hand prints "\"f\"" as expected
I ended up writing my own replacement function that operates on plain strings.
Compare with Ruby:
>> puts "\"\"".gsub(/\"/, "\\\"")
\"\"
=> nil