Batch converting straight quotes to smart quotes from MySQL database

904 Views Asked by At

I have a MySQL table with about 250 blog entries, all using straight quotes (" and ') instead of smart quotes (“ ” and ‘ ’). I need to take those entries and somehow do a batch find-and-replace to replace all straight quotes with smart quotes. Problem is these fields also contain HTML, so I need to ensure all quotes within <> tags are ignored.

I've exported the appropriate fields and opened up in Sublime Text thinking I could do regex find-and-replace. It's there that I hit a wall, though.

Suggestions?

1

There are 1 best solutions below

11
On

I don't know how to enter the smart quotes in Sublime Text 2, but I tested the following regex (in Sublime Text 2 itself) for the single quote case using [] as the replacement characters:

Find what:    ((?:[^<'>]*|<.*?>)*)'(.*?)'
Replace with: $1[$2]

Hopefully this will help.

Here is rubular for it, showing matches.