Replace (/ "([^"] *) "/ g," $1' ") has the same effect as replace (/" / g, "'"). Why use the former?

in the introduction to the replace () method of w3school, there is an example:

// 
name = ""a", "b"";
name.replace(/"([^"]*)"/g, ""$1""); // "a", "b"

and replace it with the following abbreviation

name = ""a", "b"";
name.replace(/"/g, """); // "a", "b"

the effect is the same. If the latter can be realized, why use the former? Is it just to illustrate the use of $1 or is it beneficial?


these two regular expressions have different meanings
you replace (/ "/ g,"'"); converts all " into '

.

and the expression replace (/ "([^"] *) "/ g,"'$1' "); wraps all double quotation marks without the value of double quotation marks in the middle, replacing it with single quotation marks.

for example, there is a string like this: '"dsds" dsd "," ggfgfg "
the replacement result is: `

'"dsds"dsd","ggfgfg"'.replace(/"/g, "'");//:'dsds'dsd','ggfgfg'
'"dsds"dsd","ggfgfg"'.replace(/"([^"]*)"/g, "'$1'"); //: 'dsds'dsd','ggfgfg"
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35a26-2b800.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35a26-2b800.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?