Pattern matching email address using regular expressions
Filter email address with regular expressions: I am new to regular expressions and was hoping someone might be able to help out.
I am trying to pattern match an email address string with the following format:
FirstName.LastName@gmail.com
I want to be sure that there is a period somewhere before the '@' character and that the characters after the '@' character matches gmail.com
Thanks, Brad
You want some symbols before and after the dot, so I would suggest .+..+@gmail.com
.
.+
means any symbols (.) can appear 1 or more times (+)
.
means the dot symbol; screened with backslash to suppress the special meaning of .
@gmail
and com
should be matched exactly.
See also Regular Expression Basic Syntax Reference
EDIT: gmail rules for account name only allow latin letters, digits, and dots, so a better regex is
[a-zA-Z0-9]+.[a-zA-Z0-9]+@gmail.com
You don't even need regex since your requirements are pretty specific. Not sure what language you're using, but most would support doing a split on @
and checking for a .
. In python:
name, _, domain = email.partition('@')
if '.' in name and domain == 'gmail.com':
# valid
你没有告诉我们你需要什么类型的正则表达式,但是这个例子将适合大多数:
.*..*@gmail.com
链接地址: http://www.djcxy.com/p/92638.html
上一篇: 正则表达式来验证逗号分隔的电子邮件地址?
下一篇: 使用正则表达式匹配电子邮件地址