How to remove the [ and ] in a string result

Viewed 47

example output: [EU Ecolabel (EU Flower),Cradle to Cradle (C2C) - Gold]

str.replace(/,/g, "||" ); works fine to replace the comma with a double-pipe symbol

I just cannot get the 2 brackets removed with: return str2.replace(/(\[|\]),/," ");

Any suggestions are welcome, thanks! HJ

function main(args, values) {
   var str = inriverctx.GetExtraRelatedEntityFieldDisplayValue("Certification","CertificationName","","CertificationItems","0");
   var str2 = str.replace(/,/g, "||" );
   return str2.replace(/(\\[|\\]),/," ");
}
1 Answers

Use

str.replace(/,/g, "||" ).replace(/[\][]/g, '')

See regex proof.

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  [\][]                    any character of: ']', '['
Related