简体   繁体   中英

Remove escape characters string using jQuery/JavaScript

I want to remove the escape charecters from a string using jquery.

I know about the "escape()" in jquery but the issue is

For example I want to remove the escape charecters from the string "http://www.abc.com" if we

use escape() we get the result like this 'http%3A//www.abc.com' but i want the result like

'http//www.abc.com'. How it possible using jquery?

There's nothing in jQuery about unescpaing.

Core javascript has escape() and unescape() function.

var url = 'http://www.abc.com';

var escaped_url = escape(url);

console.log(escaped_url); // logs 'http%3A//www.abc.com'

console.log(unescape(escpaed_url)) // logs 'http://www.abc.com'

ie

unescape(escape('http://www.abc.com')) === 'http://www.abc.com'

Use a regex? replace(/[^a-z0-9\\s]/gi, '') function? Amend to characters you want to keep

escape() encodes the special characters! To remove the characters, use for example replaceAll(String regex, String replacement) .

In the regex -part you can insert all of the special character you want to remove.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM