Replace two double quotes with single one using jquery

14,690

try this:

mystring = mystring.replace(/""/g, '"');

The regex captures two double quotes and replaces them with one. We're using a regex to replace more than a single match (JavaScript's replace will only replace the first one).

Note that the second argument to replace is a string. To represent " in a string we need to escape it: "\"", or use a single quote string: '"'. JavaScript supports both.

Share:
14,690
Prasad
Author by

Prasad

Updated on August 03, 2022

Comments

  • Prasad
    Prasad over 1 year

    How do I replace two double quotes into single one using jQuery?

    For example: I need to replace

    Sam is at his ""Home""

    to

    Sam is at his "Home"

    Looking for something similar to this regex (which replaces double quotes to single quotes):

    mystring.replace(/"/g, "'")