これは難しいかもしれません。
標準grep
の機能には制限があります。正規表現が依存する先読みアサーションを認識しない POSIX 拡張正規表現のみをサポートします。
マシンにGNU がある場合は、またはパラメータgrep
を渡して、Perl 互換の正規表現を使用できるようにします。次に、正規表現が機能するはずです。-P
--perl-regexp
私のコメントで述べたように、そのままの正規表現はパスワードの検証には適していません。次のようなパスワード、z000
または空の文字列さえも許可します。
( # Either match and capture...
^ # Start of the string
( # Match (and capture, uselessly in this case)
[zZ] # case-insensitive z
\d{3} # three digits
)* # zero(!) or more times
$ # until the end of the string
) # End of first group.
| # OR
( # match and capture...
(?=.{9,}) # a string that's at least 9 characters long,
(?=.*?[^\w\s]) # contains at least one non-alnum, non-space character,
(?=.*?[0-9]) # at least one ASCII digit
(?=.*?[A-Z]) # at least one ASCII uppercase letter
.*?[a-z].* # and at least one ASCII lowercase letter
) # no anchor to start/end of string...
より良い使用
^(?=.{9})(?=.*?[^\w\s])(?=.*?[0-9])(?=.*?[A-Z]).*?[a-z].*$