その正規表現は失敗しませんが.cat
、一致.com
すると、表示されている動作の原因となる他の問題が発生する必要があります。次の説明がありregex
ます。
^([\w]+)(\.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/
^ Start of string
1st Capturing group ([\w]+)
Char class [\w] infinite to 1 times matches one of the following chars: \w
\w Word character [a-zA-Z_\d]
2nd Capturing group (\.[\w]+) infinite to 0 times
\. Literal .
Char class [\w] infinite to 1 times matches one of the following chars: \w
\w Word character [a-zA-Z_\d]
@ Literal @
3rd Capturing group ([\w-]+\.) 5 to 1 times
Char class [\w-] infinite to 1 times matches one of the following chars: \w-
\w Word character [a-zA-Z_\d]
\. Literal .
4th Capturing group ([A-Za-z]) 4 to 2 times
Char class [A-Za-z] matches one of the following chars: A-Za-z
$ End of string
そして 2 番目は、適切なエスケープが与えられた場合、両方を受け入れます (ほとんどの言語では、バックスラッシュが 2 つあると両方が一致しなくなります)。
/^\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,6}$/
^ Start of string
\w Word character [a-zA-Z_\d]
Char class [-._\w] infinite to 0 times matches one of the following chars: -._\w
\w Word character [a-zA-Z_\d]
\w Word character [a-zA-Z_\d]
@ Literal @
\w Word character [a-zA-Z_\d]
Char class [-._\w] infinite to 0 times matches one of the following chars: -._\w
\w Word character [a-zA-Z_\d]
\w Word character [a-zA-Z_\d]
\. Literal .
\w 6 to 2 times Word character [a-zA-Z_\d]
$ End of string