preg 匹配电子邮件和姓名从 到

发布于 2024-08-11 07:20:05 字数 780 浏览 2 评论 0原文

我想找到以下格式的姓名和电子邮件(如果您知道在邮件应用程序中用于发送电子邮件的任何其他格式,请在评论中告诉:))

我如何知道以下格式字符串的姓名和电子邮件(它的一个 )字符串,可以是以下任何格式):

 - [email protected]
 - james [email protected]
 - "James Jordan" <[email protected]> (gmail format)
 - janne - [email protected] (possible format)

i want to find name and email from following formats (also if you know any other format that been getting use in mail application for sending emails, please tell in comment :))

how can i know name and email for following format strings (its one string and can be in any following format):

 - [email protected]
 - james [email protected]
 - "James Jordan" <[email protected]> (gmail format)
 - janne - [email protected] (possible format)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情独悲 2024-08-18 07:20:05

答案很简单,至少对于电子邮件部分来说是这样。其余的可以特殊处理。

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

证明我没有疯。

The answer is straightforward, at least for the email portion. The rest can be special-cased away.

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

Proof I'm not insane.

锦上情书 2024-08-18 07:20:05

如果只有这些字符串,则比简单的正则表达式需要更多的工作。例如,您的第一个示例不包含全名,仅包含电子邮件,因此,您必须使用 Microsoft Live ID API 来检索该信息......事实证明这非常困难。

你到底想做什么?也许还有另一种方法?

If you only have those strings, it is going to require more work than a simple regular expression. For instance, your first example doesn't include the full name, it is only the e-mail, thus, you would have to use the Microsoft Live ID API to retrieve that information...and that turns out to be really hard.

What exactly are you trying to do? Perhaps there is another way?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文