Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace parentheses in URL strings [duplicate]

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?

like image 903
Laeeq Avatar asked Aug 22 '13 06:08

Laeeq


People also ask

How do I remove parenthesis from a string?

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.

When should I use special characters in a URI string?

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).

How do I replace multiple occurrences in a string literal?

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.

How can I shorten the URL of a website?

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


1 Answers

Use the string.replace() method.

url = url.replace(/\(/g, '%28').replace(/\)/g, '%29');
like image 197
Barmar Avatar answered Oct 02 '22 20:10

Barmar