【发布时间】:2023-03-12 19:21:01
【问题描述】:
感谢另一个问题:removing BBcode from textarea with Javascript
我设法创建了这个:
http://jsfiddle.net/hVgAh/1/
text = $('textarea').val();
while (text.match(/\[quote.*\[\/quote\]/i) != null) {
//remove the least inside the innermost found quote tags
text = text.replace(/^(.*)\[quote.*?\[\/quote\](.*)$/gmi, '\$1\$2');
}
text = text.replace(/\[\/?[^\[\]]+\]/gmi,'');
// now strip anything non-character
//text = text.replace(/[^a-z0-9]/gmi, '');
char = text.length;
$('div').text(text);
此代码确实删除了引用 bbcode(以及其他 BBcode),但它只删除了最深的引用的内容,或者它会看到的最后一个引用。我认为这样做的原因是正则表达式是贪婪的。但我试图通过添加? 使其不贪心,但我没有工作:http://jsfiddle.net/hVgAh/2/
我需要删除所有引号及其内容。我该怎么做?
【问题讨论】:
标签: javascript regex bbcode phpbb3