MokiNex
MokiNex

Reputation: 879

replace comma with whitespace

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

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

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

Related Questions