在您的第一个表达式中,如果您在最后一个.*?
之前转义了\.
点,它将会匹配您的第二个表达式完全匹配整行。匹配但不包括@
你可以做..
对于域使用:
^@(\S+\.[^\s]+)$
正则表达式:
^ the beginning of the string
@ '@'
( group and capture to \1:
\S+ non-whitespace (all but \n, \r, \t, \f, and " ") (1 or more times)
\. '.'
[^\s]+ any character except: whitespace (1 or more times)
) end of \1
$ before an optional \n, and the end of the string
参见live demo
对于用户使用:
^@([^\s.]+)$
正则表达式:
^ the beginning of the string
@ '@'
( group and capture to \1:
[^\s.]+ any character except: whitespace or '.' (1 or more times)
) end of \1
$ before an optional \n, and the end of the string
见live demo
这是匹配@的下一行吗? – Joec