Saving text with special characters in them

I would like to save some regex to the database. An example would be this (?s)(?<=\"}">)(.*?)(?=\<\/span\><\/a>)

The problem is that " gets saved as ". How do I save and retrieve exactly that is written. For instance this forum post allowed me to type the characters " without converting them when I saved the post, how do I get SC to do the same?

On research it appears the issue might be to do with the default settings for htmlspecialchars and htmlspecialchars_decode. I need to prevent both. Since I need to preserve exactly the text for regex to work, I cannot convert all the " to " or vice versa, just to prevent any changes at all. Other characters that may fall under this banner are > < ? & and ’ . However since only " is converted, it makes me wonder what is doing it. I have PHP 7 and MySQL (MariahDB) . Any ideas whether this is a MySQL thing, PHP thing or SC thing? And how to override it?

New Update: not MySQL when saved as TEXT.
New Update 2: More problematic than I thought. Searching for the string OnBeforeUpdate returns nothing…so I cannot even substitute the text and then swap it back later.

if (strpos($script, ‘"’) !== false) {
sc_alert(‘true for quot’);
}
…returns nothing…OK for SPAN though

So SC is internally converting " BEFORE anything has been done to the text. Updating MySQL with " is no problem as long as it does not go near a text field first.Even if you set it to a $variable from a text field, what is picked up is the translation of the text not the text itself. Same for & < and > but not for ’ . It seems SC is messing up my text before I even have a chance to capture it. Not good. Shouldn’t the “Save HTML tags” option extend to html special characters too???