w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
javascript replace single quote with double single quote issue

If it's safe to assume that there won't be three or more quotes in a row, try this:

str.replace(/'+/g,"''")

If the assumption is not safe, and you just want to replace "a quote by itself" with two quotes, leaving multi-quotes alone, try this:

str.replace(/''?('*)/g,"''$1");

That being said, you might want to look into why it's replacing more than once in the first place ;)





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.