java 邮件提取正则表达式?
我想要一个从字符串中提取电子邮件地址的正则表达式(使用 Java 正则表达式)。
这确实有效。
I would like a regular expression that will extract email addresses from a String (using Java regular expressions).
That really works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是真正有效的正则表达式。
我花了一个小时在网上冲浪并测试不同的方法,
尽管谷歌将这些页面排名最高,但其中大多数都不起作用。
我想与您分享一个有效的正则表达式:
这是原始链接:
http://www.mkyong。 com/正则表达式/如何使用正则表达式验证电子邮件地址/
Here's the regular expression that really works.
I've spent an hour surfing on the web and testing different approaches,
and most of them didn't work although Google top-ranked those pages.
I want to share with you a working regular expression:
Here's the original link:
http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/
我必须添加一些破折号才能允许它们。所以爪哇语的最终结果是:
I had to add some dashes to allow for them. So a final result in Javanese:
将这个正则表达式测试器插件安装到 eclipse 中,您将有大量时间测试正则表达式
http://brosinski.com/regex/。
注意事项:
在插件中,仅使用一个反斜杠进行字符转义。但是,当您将正则表达式转录为 Java/C# 字符串时,您必须将它们加倍,因为您将执行两次转义,首先从 Java/C# 字符串机制转义反斜杠,然后第二次转义实际的正则表达式字符转义机制。
用圆括号/省略号将要捕获其文本的正则表达式部分括起来。然后,您可以使用 Java 或 C# 正则表达式中的组函数来找出这些部分的值。
([_A-Za-z0-9-]+)(\.[_A-Za-z0-9-]+)@([A-Za-z0-9]+)(\.[A- Za-z0-9]+)
例如,使用上面的正则表达式,以下字符串
产生的
Group 0 始终捕获整个匹配的字符串。
如果您没有用省略号括起任何部分,您将只能检测到匹配项,但无法捕获文本。
创建几个正则表达式可能比创建一个长的包罗万象的正则表达式更容易混淆,因为您可以通过编程方式一一测试,然后决定应该合并哪些正则表达式。尤其是当您发现以前从未考虑过的新电子邮件模式时。
Install this regex tester plugin into eclipse, and you'd have whale of a time testing regex
http://brosinski.com/regex/.
Points to note:
In the plugin, use only one backslash for character escape. But when you transcribe the regex into a Java/C# string you would have to double them as you would be performing two escapes, first escaping the backslash from Java/C# string mechanism, and then second for the actual regex character escape mechanism.
Surround the sections of the regex whose text you wish to capture with round brackets/ellipses. Then, you could use the group functions in Java or C# regex to find out the values of those sections.
([_A-Za-z0-9-]+)(\.[_A-Za-z0-9-]+)@([A-Za-z0-9]+)(\.[A-Za-z0-9]+)
For example, using the above regex, the following string
yields
Group 0 is always the capture of whole string matched.
If you do not enclose any section with ellipses, you would only be able to detect a match but not be able to capture the text.
It might be less confusing to create a few regex than one long catch-all regex, since you could programmatically test one by one, and then decide which regexes should be consolidated. Especially when you find a new email pattern that you had never considered before.
有点晚了但是还可以。
这是我用的。只需将其粘贴到 FireBug 的控制台中并运行即可。在网页上查找“文本区域”(最有可能位于页面底部),其中将包含 A 标记中找到的所有电子邮件地址的单独列表。
a little late but ok.
Here is what i use. Just paste it in the console of FireBug and run it. Look on the webpage for a 'Textarea' (Most likely on the bottom of the page) That will contain a , seperated list of all email address found in A tags.
Java 的内置电子邮件地址模式 (
模式。 EMAIL_ADDRESS
)完美运行:The Java 's build-in email address pattern (
Patterns.EMAIL_ADDRESS
) works perfectly: