gpt4 book ai didi

从文本中删除 bb_quotes ([quote..] [/quote]) 的 Javascript

转载 作者:行者123 更新时间:2023-11-30 14:00:31 27 4
gpt4 key购买 nike

目标是使用 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,''));

关于从文本中删除 bb_quotes ([quote..] [/quote]) 的 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56386259/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com