我的输入:(((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))
当我有这个字符串),(
DEMO:
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);

答案 0 :(得分:4)
您应该在结果中加入)(
:
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
是一种字符串。