in reply to Regex matching on anywhere but the beginning or end of a line

s{ (?<!\A) # "beginning of string" doesn't match before current char " (?!\z) # "end of string" doesn't match behind current char } {""}xg;

See perlre.

That said, take dws's advice. Trying to manually quote all dangerous characters will get you in trouble because inadvertantly you'll forget some edge case. Even if not, metacharacters or edge cases may be introduced or removed in later versions of the database engine, breaking your quoting effort. The database driver is always kept in sync with the engine - let it do its job.

Makeshifts last the longest.