gpt4 book ai didi

javascript - 用空格替换逗号

转载 作者:行者123 更新时间:2023-11-29 17:46:06 26 4
gpt4 key购买 nike

我的输入:(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6)),((tttt,tttt)),((and,lol )),((hbhbhbhbhbh))

我的输出:(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6) (tttt,tttt) (and,lol) (hbhbhbhbhbh))

我预期的结果:(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6) ((tttt,tttt)) ((and,lol )) ((hbhbhbhbhbh))

当我有这个字符串时,我想用空格替换逗号 ),(

演示:

 var txt="(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6)),((tttt,tttt)),((and,lol)),((hbhbhbhbhbh))"
var finalResult=txt.replace(/[)],[(]/g," ");

console.log("Result:",finalResult);

最佳答案

您应该在结果中包含 )(:

var txt = "(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6)),((tttt,tttt)),((and,lol)),((hbhbhbhbhbh))"
var finalResult = txt.replace(/[)],[(]/g, ") (");

console.log("Result:", finalResult);

我得到以下输出:

Result: (((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6)) ((tttt,tttt)) ((and,lol)) ((hbhbhbhbhbh))

此外,请注意您不需要 .toString() 函数,因为原始 txt 是一种字符串。

关于javascript - 用空格替换逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553020/

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