在我的前端,我在javascript中有一个正则表达式来检测电子邮件是否正确。
^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$
.NET 上的当前后端正则表达式验证是:
Regex.IsMatch(email, @"A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)Z", RegexOptions.IgnoreCase);
我想用javascript替换.NET正则表达式,但我真的"迷失"在开始/结束字符中。
在 .NET 正则表达式中,A
和Z
的实用程序是否与我的 JavaScript 中的 ^
和 $
相同?
我试图按如下方式替换我的 .NET 正则表达式,但它无法检测到有效的字符串,即使在 Javascript 中它是正确的:
Regex.IsMatch(email, @"A(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))Z", RegexOptions.IgnoreCase);
^ - The match must occur at the beginning of the string or line. $ - The match must occur at the end of the string or line, or before n at the end of the string or line. A - The match must occur at the beginning of the string only (no multiline support). Z - The match must occur at the end of the string, or before n at the end of the string.