在您的第一個表達式中,如果您在最後一個.*?
之前轉義了\.
點,它將會匹配您的第二個表達式完全匹配整行。匹配但不包括@
你可以做..
對於域使用:
^@(\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