If they're either not followed by a comma or a ) (close bracket) or if a ( (open bracket) precedes it.
I need it to clean up an SQL import file with 50k+ rows that contains ' (apostrophe) in between ' (apostrophe) and ' (apostrophe). I could rewrite the PHP script to consider this issue, but the solution I am asking you about would save me a lot of time.
Example:
INSERT INTO `base__raw`
(`txtField1`, `txtField2`)
VALUES
('Good string', 'This is a good string'),
('Bad string', 'aramäisch ab a' = Vater');
After "replacing" all said apostrophes by putting a backslash ahead of them:
INSERT INTO `base__raw`
(`txtField1`, `txtField2`)
VALUES
('Good string', 'This is a good string'),
('Bad string', 'aramäisch ab a\' = Vater');