替换两个引号之间的字符串

maz*_*lix 3 javascript regex jquery

我想把一个字符串str = "hello, my name is \"michael\", what's your's?"变成"hello, my name is <span class="name">michael</span>

我怎么能用javascript做到这一点?我知道如何进行str替换,但是如何获取我选择/替换它的内容.

谢谢!!!

dav*_*vin 8

str = "hello, my name is \"michael\", my friend's is \"bob\". what's yours?";
str.replace(/"([^"]+)"/g, '<span class="name">$1</span>');
Run Code Online (Sandbox Code Playgroud)

输出:

hello, my name is <span class="name">michael</span>, my friend's is <span class="name">bob</span>. what's your's?
Run Code Online (Sandbox Code Playgroud)