javascript |使用正则表达式查找和替换引号

时间:2013-06-17 06:03:38

标签: javascript regex

我有一个如下字符串:

[quote="username"]This is a comment string[/quote]

模式1:用户名 模式2:这是一个评论字符串

是否可以将其替换为:

<div class="myclass">
   <b>username</b>
   <i>This is a comment string</i>
</div>

感谢。

1 个答案:

答案 0 :(得分:0)

尝试

'[quote="username"]This is a comment string[/quote]'.replace(/\[quote="(.*?)"\](.*?)\[\/quote\]/, function(text, g1, g2, pos, content){console.log('a', g1, g2); return 'd'})
相关问题