my input is var email = "xyz+wex+rr%40gmail.com";
i need output as
xyz wex rr @ gmail.com
i have tried with this below regex , i can only remove + from my string how to replace %40 with @
email .replace(/+/g, " ");
my input is var email = "xyz+wex+rr%40gmail.com";
i need output as
xyz wex rr @ gmail.com
i have tried with this below regex , i can only remove + from my string how to replace %40 with @
email .replace(/+/g, " ");
var email = "xyz+wex+rr%40gmail.com";
email = decodeURIComponent(email).replace(/\+/g, " ");
console.log(email);
decodeURIComponent decodes things like %40. It only does not replace the +
signs with spaces, so this is done with a RegEx, escaping the plus sign, which has a special meaning in RegEx.
You can use unescape function to first unescape the string and than replace +
with
Try this one
var email = unescape("xyz+wex+rr%40gmail.com").replace(/[+]/g, " ");
console.log(email)
As @Florian Albrecht said that unescape
is deprecated so deprecated Florian's answer is better
Here is required solution,
email.replace(/\+/g, " ").replace(/\%40/g, "@")
var email = "xyz+wex+rr%40gmail.com";
console.log(email.replace(/\+/g, " ").replace(/\%40/g, "@"))
Result: xyz wex rr@gmail.com
Please run the above snippet