JavaScript 正则表达式匹配 [[quote][/quote]]

标签 javascript regex

var quote = 'some text here [[quote=bob]This is some text bob wrote[/quote]] other text here';

我正在尝试获取[[quote=bob]这是鲍勃写的一些文字[/quote]]

我正在使用: match(/[[quote=(.*?)](.*?)[/quote]]/)[1]

但它给了我这里一些文字[[quote=bob]这是鲍勃写的一些文字[/quot

最佳答案

试试这个:

var quote = 'some text here [[quote=bob]This is some text bob wrote[/quote]] other text here';

console.log( quote.match(/(\[\[quote=(.*?)\](.*?)\[\/quote\]\])/) );
// [1] => "[[quote=bob]This is some text bob wrote[/quote]]"
// [2] => "bob"
// [3] => "This is some text bob wrote"

关于JavaScript 正则表达式匹配 [[quote][/quote]],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26807458/

相关文章:

python - 如何去除unicode字符串中的空格

json - 如何在 Elasticsearch 中进行部分匹配?

javascript - 如果单击子元素,则不要更改父元素的颜色

javascript - Electron - 如何将 base64 dataUrl 保存到文件

javascript - 通过 ajax 加载内容时 jQuery 的本地时间插件失败

javascript - 在文本字段左侧设置错误 Div 定位 - Jquery 验证引擎

c# - 使用正则表达式模式提取键值对

删除字符串中的所有 "H",除了包括 "CH"的那些

java - 正则表达式匹配问题

javascript - Jquery Chosen 在下拉列表中获取未选择值的 Id