替换两个引号之间的字符串
我想把一个字符串str = "hello, my name is \"michael\", what's your's?"
进入"hello, my name is michael
我怎么能用javascript做到这一点? 我知道如何进行str替换,但是如何获取我选择/替换它的内容。
谢谢!!!
str = "hello, my name is \"michael\", my friend's is \"bob\". what's yours?"; str.replace(/"([^"]+)"/g, '$1');
输出:
hello, my name is michael, my friend's is bob. what's your's?
虽然@davin的答案是正确的,但我认为你会想要处理双引号的实例。
var str = "hello, my name is \"michael\", what's your's? Is is \"James\" or is it blank:\"\"";
用*
代替+
就足够了:
/"([^"]*)"/g
虽然您可以通过简单的首次解析搜索完全丢弃它并替换:
str.replace(/""/,"")