javascript - Javascript 从文本中删除 bb_quotes ([quote..] [/quote])
问题描述
目标是使用 Javascript (vanilla) 删除介于 [quote] [/quote] 和 [quote=something] [/quote] 之间的所有文本(包括)(不区分大小写)。如果在删除引号后存在双空格,最好也删除它们。我试过这个Javascript如下,即:
t.replace(/\[quote.*\](.*?)\[\/quote\]/gi,'')
,但我没有得到正确的结果。正确的方法是什么?
var t='Starting [QUOTE]this should be ignored hello[/quote] it. This is not quote and [quote=frank]HELLO quotes[/quote] Marky Mark 84WD. Last [quote=irene]try.[/quote]';
console.log(t.replace(/\[quote.*\](.*?)\[\/quote\]/gi,''));
//Current result: Starting.
//Expected result: Starting it. This is not quote and Marky Mark 84WD. Last
var t='[Quote]this should be ignored hello[/quote]. This is not quote and [quote=frank]HELLO quote[/quote] Marky Mark 84WD.';
console.log(t.replace(/\[quote.*\](.*?)\[\/quote\]/gi,''));
//Current result: Marky Mark 84WD.
//Expected result: . This is not quote and Marky Mark 84WD.
解决方案
您可以使用/\[(quote)[^\]]*](.*?)\[\/\1\]/gi
来实现过滤:
var t='Starting [QUOTE]this should be ignored hello[/quote] it. This is not quote and [quote=frank]HELLO quotes[/quote] Marky Mark 84WD. Last [quote=irene]try.[/quote]';
console.log(t.replace(/\[(quote)[^\]]*](.*?)\[\/\1\]/gi,''));
var t='[Quote]this should be ignored hello[/quote]. This is not quote and [quote=frank]HELLO quote[/quote] Marky Mark 84WD.';
console.log(t.replace(/\[(quote)[^\]]*](.*?)\[\/\1\]/gi,''));
推荐阅读
- c# - 如何在此方法中增加 result 关键字?在硒 C#
- java - 面对 SpringBoot Security 模块登录错误
- javascript - 从普通 javascript 访问 python 方法
- r - 创建具有许多缺失值的每日平均值的问题
- asp.net-core - 如何修复:尽管在构建管道中设置了变量,但在 Azure Devops 中,连接字符串为空
- php - 即使缺少记录,也每天汇总统计信息
- python - 如何为具有附加功能的函数创建装饰器?
- android - 手机默认短信中的“&”字符后内容消失
- c# - 如何修复我的 2D 敌人角色在角色接近其范围时发出警告而不是滑动而不是停止
- r - ggplot 中的线连接所有点,而不仅仅是组中的点