Javascript examples for RegExp:Bracket
Use regex to Remove comma only if it is not in brackets
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){// w ww . j a va 2 s . c om var string = 'filters=fuelType=D,make=[BMW,CITROEN,DACIA],price=(0,100)'; var result = string.replace(/,\s*(?=[^)^\]]*(?:\(|\[|$))/g, '&'); console.log(result); } </script> </head> <body> </body> </html>