Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
この正規表現:
^[a-zA-Z0-9 -.,()/\n/\r]+$
.NET では常に一致します
「#」または「$」または「!」または「%」または「&」または「*」または「+」
明確にするために、この行:
Regex.IsMatch("!", @"^[a-zA-Z0-9 -.,()/\n/\r]+$");
true を返します。なぜそれが起こるのですか?
文字クラスのハイフンは、最初または最後の位置にある必要があります。それ以外の場合は、エスケープする必要があります。それはうまくいくはずです:
^[a-zA-Z0-9 .,()/\n/\r-]+$
または:
^[-a-zA-Z0-9 .,()/\n/\r]+$
^[a-zA-Z0-9 \-.,()/\n/\r]+$