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?
You can also use a regular experession if you're looking for parenthesis, you just need to escape them. This will remove all ( and ) in the entire string. Show activity on this post.
As a rule of thumb, avoid using the special characters above when formulating a URI string (filename), and I recommend using the hyphen (-) instead of the underscore (_) (as all search engines recognize the hyphen as a space separator, but the same is not true for the underscore. And older browsers do not correctly interpret the underscore in CSS).
That's because to replace multiple occurrences you must use a regex as the search string where you are using a string literal. As you have found searching by strings will only replace the first occurrence. Show activity on this post.
One workaround is to use a service like TinyURL or Bitly to shorten the URL. Not the answer you're looking for? Browse other questions tagged
Use the string.replace()
method.
url = url.replace(/\(/g, '%28').replace(/\)/g, '%29');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With