我正在尝试理解当前用于验证网站上电子邮件地址输入的正则表达式。此电子邮件地址的值用于填充目标系统;验证可以用简单的英语表达。
我希望能够通过使用示例突出显示网站验证的电子邮件地址强加了目标系统中不需要的验证规则。为此,我已经从开发人员那里获得了正则表达式,并且需要一些帮助来翻译它以便用简单的英语来理解它:
^[_A-Za-z0-9_%+-]+(\\.[_A-Za-z0-9_%+-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,4})$
到目前为止,我已经从previous post获得了一些了解。
......这似乎证实了以下内容:
^
=匹配的字符串必须从此处开始,并且仅从此处开始
[ ]
=匹配括号内的任何字符,但只匹配一个字符。
我不确定“只匹配一个”的相关性。有人可以建议吗?
\+
=匹配前一个表达式至少一次,无限次。
大概这意味着前面的表达式是指前面方括号中包含的字符,可以无限次重复吗?
()
=使括号内的所有内容成为一个组(并使它们可引用)。
我不确定这可能意味着什么。
\\.
=匹配文字句号(.
)
然后我们重复了方括号内容,虽然我不确定这里的相关性是什么,因为最初的方括号字符类可以无限次重复?
@
=匹配文字@
符号
最后一个括号似乎与顶级域匹配,该域必须至少包含2个字符但不超过4个字符。
我认为我的主要问题是理解圆括号的相关性,因为我无法理解它们在方括号添加之外的内容。
非常感谢任何帮助。
答案 0 :(得分:0)
^[_A-Za-z0-9_%+-]+(\\.[_A-Za-z0-9_%+-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,4})$
Assert position at the beginning of the string «^»
Match a single character present in the list below «[_A-Za-z0-9_%+-]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
The character “_” «_»
A character in the range between “A” and “Z” «A-Z»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
One of the characters “_%” «_%»
The character “+” «+»
The character “-” «-»
Match the regular expression below and capture its match into backreference number 1 «(\\.[_A-Za-z0-9_%+-]+)*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Note: You repeated the capturing group itself. The group will capture only the last iteration. Put a capturing group around the repeated group to capture all iterations. «*»
Match the character “\” literally «\\»
Match any single character that is not a line break character «.»
Match a single character present in the list below «[_A-Za-z0-9_%+-]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
The character “_” «_»
A character in the range between “A” and “Z” «A-Z»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
One of the characters “_%” «_%»
The character “+” «+»
The character “-” «-»
Match the character “@” literally «@»
Match a single character present in the list below «[A-Za-z0-9]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “A” and “Z” «A-Z»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the regular expression below and capture its match into backreference number 2 «(\\.[A-Za-z0-9]+)*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Note: You repeated the capturing group itself. The group will capture only the last iteration. Put a capturing group around the repeated group to capture all iterations. «*»
Match the character “\” literally «\\»
Match any single character that is not a line break character «.»
Match a single character present in the list below «[A-Za-z0-9]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “A” and “Z” «A-Z»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
Match the regular expression below and capture its match into backreference number 3 «(\\.[A-Za-z]{2,4})»
Match the character “\” literally «\\»
Match any single character that is not a line break character «.»
Match a single character present in the list below «[A-Za-z]{2,4}»
Between 2 and 4 times, as many times as possible, giving back as needed (greedy) «{2,4}»
A character in the range between “A” and “Z” «A-Z»
A character in the range between “a” and “z” «a-z»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»