var string = 'https://opt.portal.co.uk/index/stepregistration/Username/test%40test.es/nextstep/1/lang/es?kmi=K54Nv1RdlV71hhiLEdPg0UZ0%3D&_ga=1.217245974.18890806.1485212';
电子邮件的编码方式如下test%40test.es
使用 JavaScript(无 jQuery)获取此电子邮件地址的方法是什么?
最佳答案
您可以使用以下方式完成此操作:
- 使用decodeURIComponent()解码 URI
- 使用
正则表达式
提取电子邮件地址
var string = 'https://opt.portal.co.uk/index/stepregistration/Username/test%40test.es/nextstep/1/lang/es?kmi=K54Nv1RdlV71hhiLEdPg0UZ0%3D&_ga=1.217245974.18890806.1485212';
var email = decodeURIComponent(string).match(/\w+@\w+\.\w+/g)[0];
console.log(email);
关于JavaScript。如何从字符串中提取 URI 编码的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42720962/