How to strip all urlencode characters in JavaScript

Practice



We have characters matching the pattern %XX

that is, the string contains a percent sign followed by 2 more arbitrary latin or numeric characters.

 

We put together a regular expression that replaces every match with nothing, i.e. deletes them.

Example

 
href = document.location.href;
console.log(href );
https://docs.com/%D0%9D%D0%B0%D1%81%D1%82%D1%80%D0%BE%D0%B9%D0%BA%D0%B8-6
href =href.replace(/\%(..)/g, '');
console.log(href );
 
after that you get

https://docs.com/-6

 

But that way any 2 characters get removed, whereas we need to remove exactly english letters and digits, so it is better to use this regular expression for stripping urlencode

 

href.replace(/\%([A-Z0-9]{2})/g, '');

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone