删除电子邮件扩展,但希望保持"@"但是忽略yahoo.com的部分.没有打印出@符号

Removing the email extension but want to keep the "@" but ignore the yahoo.com part. Not printing out the @ sign

本文关键字:quot com 符号 打印 yahoo 扩展 电子邮件 希望 删除      更新时间:2023-09-26

//需要帮助打印出xxx@但是从电子邮件地址中删除yahoo.com

function emailSort(){
var emails = document.getElementById("emailTextarea").value.split("'n");
var users = [],  l = emails.length, id;
while (l--)
    if ((id = emails[l].match(/('w+)'@/)) && (-1 === users.indexOf(id[1])))
      users.push(id[1]);
}

试一下

var v="abcd@yahoo.com";
console.log(v.split("@")[0]+'@');

也许你想要这样:

document.getElementById('emailTextarea').value.replace(/yahoo'.com$/, '');

您可以找到@并取到该位置的子字符串:

email.substring(0, email.indexOf('@')+1)

使用regexp,将@和随后的内容替换为@:

email.replace(/@.*/, '@')