Replace two double quotes with one using jquery

How to replace two double quotes with one using jQuery?

For example: I need to replace

Sam is in his "house"

to

Sam in his "House"

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

mystring.replace(/"/g, "'") 
+4
source share
1 answer

try the following:

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

The regular expression captures two double quotes and replaces them with one. We use regex to replace more than one match (replacing JavaScript will replace only the first).

Note that the second argument to replace is the string. To represent " in a string, we need to avoid it: "\"" or use one line of quotation marks: '"' . JavaScript supports both.

+8
source

Source: https://habr.com/ru/post/1339045/


All Articles