Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript拆分来拆分电子邮件列表_Javascript_Web_Split - Fatal编程技术网

如何使用javascript拆分来拆分电子邮件列表

如何使用javascript拆分来拆分电子邮件列表,javascript,web,split,Javascript,Web,Split,我在使用javascriptsplit方法时遇到问题。我想要一些代码来“拆分”电子邮件列表 example: test@test.comfish@fish.comnone@none.com 你是如何划分的?不管编程语言如何,你都需要编写(创建)人工智能来识别电子邮件(因为没有模式) 但既然你在问怎么做,我想你需要一个非常简单的解决方案。在这种情况下,基于.com、.net、.org拆分文本。。。 这很容易做到,但可能会产生大量无效电子邮件 更新:以下是简单解决方案的代码示例(请注意,这仅适用

我在使用javascript
split
方法时遇到问题。我想要一些代码来“拆分”电子邮件列表

example: test@test.comfish@fish.comnone@none.com

你是如何划分的?

不管编程语言如何,你都需要编写(创建)人工智能来识别电子邮件(因为没有模式)

但既然你在问怎么做,我想你需要一个非常简单的解决方案。在这种情况下,基于.com、.net、.org拆分文本。。。 这很容易做到,但可能会产生大量无效电子邮件


更新:以下是简单解决方案的代码示例(请注意,这仅适用于以3个字母结尾的所有域,如:.com、.net、.org、.biz…):

这段代码当然有缺点:

  • 它不适用于其他3字符的TLS
  • 如果域有子域,它将不起作用,例如test@test.test.com

但是我相信它有最好的时间去做它/有效电子邮件比率的百分比,因为做它所需的时间非常少。

假设你有不同的领域,比如
.com
.net
等,不能仅仅在
.com
上拆分,假设您的域名和收件人名称与您的三个示例中的每一个相同,您可能会做一些疯狂的事情,例如:

var emails = "test@test.comfish@fish.comnone@none.com"

// get the string between @ and . to get the domain name
var domain = emails.substring(emails.lastIndexOf("@")+1,emails.lastIndexOf("."));

// split the string on the index before "domain@"
var last_email = split_on(emails, emails.indexOf( domain + "@" ) );

function split_on(value, index) {
    return value.substring(0, index) + "," + value.substring(index);
}

// this gives the first emails together and splits "none@none.com" 
// I'd loop through repeating this sort of process but moving in the 
// index of the length of the email, so that you split the inner emails too

alert(last_email); 

>>> test@test.comfish@fish.com, none@none.com

你没有。如果电子邮件地址之间没有分隔符,则无法找到拆分位置。不,你不能指望“.com”是TLD,“.comf”、“.comfi”、“.comfis”、“.comn”、“.comno”、“.comnon”不是TLD。不行。不像你列出的那样。电子邮件地址和电子邮件地址之间没有任何区别。现在,如果它有一个空间,或者昏迷,那么简单的“分裂”就可以了。随着顶级域名(.com、.net、.us等)的出现,你不可能在列表中硬编码并保持最新状态,而无需大量工作。@Dr.Molle True,我本可以建议一个更好的除名器……域名和电子邮件名称是否总是与你的三个示例相同?您可能能够获取
@
之间的字符串,然后在
@
之前移动该长度并在那里拆分。作为@jcaron参数的实际示例:
foo@foo.commmm@org
。无法决定这是否应为
foo@foo.com mmm@foo.org
foo@foo.co mmmm@foo.org
由于
*.co
*.com
都是有效的TLD。我想让投票否决我的人详细说明我的答案中的错误。如果只有少数边缘案例,我不会标记你的答案,但是,如上所述,您推荐的方法不会适用于大多数情况。感谢您的澄清。在我的回答中,我已经注意到了这一点,并将其设定为最简单的解决方案。这并不意味着它是最好的!最好的显然是人工智能,但这并不是你们能很容易解释的东西。我相信他用了相同的名字和域名作为例子。我怀疑他有电子邮件gmail@gmail.com, yahoo@yahoo.com等
var emails = "test@test.comfish@fish.comnone@none.com"

// get the string between @ and . to get the domain name
var domain = emails.substring(emails.lastIndexOf("@")+1,emails.lastIndexOf("."));

// split the string on the index before "domain@"
var last_email = split_on(emails, emails.indexOf( domain + "@" ) );

function split_on(value, index) {
    return value.substring(0, index) + "," + value.substring(index);
}

// this gives the first emails together and splits "none@none.com" 
// I'd loop through repeating this sort of process but moving in the 
// index of the length of the email, so that you split the inner emails too

alert(last_email); 

>>> test@test.comfish@fish.com, none@none.com