The intention is to quote an arbitrary string so that it becomes the exact same arbitrary string when parsed (forget about interpolation for a moment). This, in my mind, yields the following rules:

1. If the string contains a NL (binary 0xa) then I assume that the quote method should translated that into the two character backslash-n. The same is true for other control characters 0x8 (tab), 0xd (CR). All with the intention that the string will again contain control characters again once it has been parsed. I assume that both the YAML and the JSON parser will see to that strings containing backslash-n will appear as 0xa when they are sent to the quote method.
2. If the string contains backslash, then that backslash has to be escaped. If it isn't, then control sequences entered as two character controls (like backslash-n) will change by the quote/parse and instead become a binary 0xa. Again, the quote/parse operation must leave the string unchanged. Please note that a string that contains a backslash when passed to the quote method has been entered as two backslashes by the user and then transformed by the YAML or JSON parser.
3. If the string contains a double quote, then that must be prefixed with a backslash in order to become a quote again when parsed.

IMO, the current regexp lacks the transformation of the control characters into their corresponding backslash construct but it is correct otherwise.