13

I have string with URL links like below. But urls are breaking when urls have parenthesis like below. The urls are breaking at the start of parenthesis in URL.

This is test http://ang.wikipedia.org/wiki/Wikipedia:Tutorial_(Wikipedia_links) 

Can we replace parentheses with other ASCII characters using javascript regex?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Laeeq
  • 403
  • 1
  • 3
  • 14
  • 1
    you can use url encode ? – backtrack Aug 22 '13 at 06:08
  • Take a look at this previous SO Post: http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript If you are having an issue with encoding, which I am assuming you do, this could get the job done in a more robust manner. – npinti Aug 22 '13 at 06:08

1 Answers1

27

Use the string.replace() method.

url = url.replace(/\(/g, '%28').replace(/\)/g, '%29');
Barmar
  • 741,623
  • 53
  • 500
  • 612