単語文字の前にあるすべてを左引用符に置き換え、単語文字に続くすべてを右引用符に置き換えることができます。
str = str.replace(/"(?=\w|$)/g, "“");
str = str.replace(/(?<=\w|^)"/g, "”"); // IF the language supports look-
// behind. Otherwise, see below.
以下のコメントで指摘されているように、これは句読点を考慮していませんが、簡単に次のことができます。
/(?<=[\w,.?!\)]|^)"/g
[編集:] Javascript のような後読みをサポートしない言語の場合、最初にすべての前面のものを置き換える限り、次の 2 つのオプションがあります。
str = str.replace(/"/g, "”"); // Replace the rest with right curly quotes
// or...
str = str.replace(/\b"/g, "”"); // Replace any quotes after a word
// boundary with right curly quotes
(後読みをサポートする言語を使用している人に役立つ場合に備えて、上記の元のソリューションを残しました)