Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一重引用符と二重引用符をバックスラッシュで 2 行ではなく 1 行でエスケープしたい。
一重引用符の例:
str = str.replace(/'/g, "\\'");
二重引用符が含まれている場合にこれを同時に行う方法はありますか?
スニファーは以下でこれに非常によく答えており、必要なすべての文字を次のようにエスケープすることになりました。
str = str.replace(/(['"&:;])/g, "\\$1");
Sniffer さん、素早い対応に感謝します。
これを試して:
str = str.replace(/(['"])/g, "\\$1");