Reputation: 879
my input:(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6)),((tttt,tttt)),((and,lol)),((hbhbhbhbhbh))
my ouput:(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6) (tttt,tttt) (and,lol) (hbhbhbhbhbh))
the result that I expected:(((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6) ((tttt,tttt)) ((and,lol)) ((hbhbhbhbhbh))
I want to replace the comma with whitespace when I have this string ),(
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);
Upvotes: 2
Views: 85
Reputation: 167172
You should be including the )(
in your result:
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);
I am getting the following output:
Result: (((text(text here))) AND (test3) Near (test4) NOT (test5) NOT (Test6)) ((tttt,tttt)) ((and,lol)) ((hbhbhbhbhbh))
Also, note that you don't need a .toString()
function here as the original txt
is a type of String.
Upvotes: 4