javascript replace char if not present another character 1

javascript replace char if not present another character

var arr = ["abc'def", "abc''de'f"];

for (i=0; i ' + arr[i].replace(/(^|[^'])'(?!')/g, "$1''") );
}

Here is what the above code is Doing:
1. The regex is looking for a single quote that is not preceded by another single quote.
2. The regex is looking for a single quote that is not followed by another single quote.
3. The regex is replacing the single quote with two single quotes.

Similar Posts