あなたが1つの正規表現が必要な場合は、試してみてください。
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$
短い説明:
^ // the start of the string
(?=.*[a-z]) // use positive look ahead to see if at least one lower case letter exists
(?=.*[A-Z]) // use positive look ahead to see if at least one upper case letter exists
(?=.*\d) // use positive look ahead to see if at least one digit exists
(?=.*[_\W]) // use positive look ahead to see if at least one underscore or non-word character exists
.+ // gobble up the entire string
$ // the end of the string
そして私はSilentGhostに同意し、[_\W]
は、ビット幅の広いかもしれません。私はこれのような文字セットに置き換えます:[[email protected]#$%^&*.,?]
(もちろん、もっと自由に追加してください!)
platform/regex-dialectは何ですか? Bartの答えは正しいですが、先読みアサーションはJavaScriptなどでは信頼できません。 – bobince
特に - 私は正規表現を学んでいます。 javascriptで使用できる代替手段はありますか? – Amarghosh
@bobinceこんにちは、私はなぜ先読みのアサーションがJavascriptで信頼できないのかを調べようとしています。これに書き直しはありますか? –