替换函数中的单/双引号

Espace single/double quotes inside replace function

本文关键字:函数 替换      更新时间:2023-09-26

我试图从转义字符的字符串中删除单引号和双引号。对于单引号'或双引号"不起作用。

有人能帮帮忙吗?

var mysting = escapedStr.replace(/^%22/g, ' '); //doesnt remove the double quotes
var mysting = escapedStr.replace(/^%27/g, ' '); //doesnt remove the single quotes
var mysting = escapedStr.replace(/^%3A/g, ' '); //does remove the SEMI COLON %3A

试试下面这段链接代码:

escape(
 unescape( mysting ).replace( /['"]/g, "" )
)

^是一个锚,表示字符串的开始。也就是说,只有当字符串%22开头时,它才会进行替换,等等。逻辑上,它只能以一个东西开头(显然是分号)。我想你只是想删除^ .