密码的正则表达式

发布于 2024-11-19 17:21:08 字数 85 浏览 5 评论 0原文

我需要帮助创建密码正则表达式。 密码必须包含至少 4 个字符、字母(大写和小写)、数字和特殊字符 - 不含空格。

msn 类似正则表达式。

I need help creating a password regex.
A password must contain at least 4 characters, letters (uppercase and lowercase), numbers and special characters - no spaces.

msn like regular expression.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坚持沉默 2024-11-26 17:21:08

该正则表达式有效 - 请参阅下面的测试数据和输出:

^(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.* )(?=.*[@#$%^&+=i.,!?:;*/])

passwords.txt 中的测试数据(只有第一个应该通过):

aB#1
aB #1
ab#1
AB#1
aB#a
aB1a
aB1

mac-osx> grep -P '^(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.* )(?=.*[@#$%^&+=i.,!?:;*/])' passwords.txt
aB#1

您可以将所需的任何额外“特殊字符”添加到最后一个前瞻正则表达式的字符类中。

This regex works - see test data and output below:

^(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.* )(?=.*[@#$%^&+=i.,!?:;*/])

Test data in passwords.txt (only the first should pass):

aB#1
aB #1
ab#1
AB#1
aB#a
aB1a
aB1

mac-osx> grep -P '^(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.* )(?=.*[@#$%^&+=i.,!?:;*/])' passwords.txt
aB#1

You can add whatever extra "special characters" you need into the last look ahead regex's character class.

幽蝶幻影 2024-11-26 17:21:08

使用这个:

(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[#&*%])^\S*$

如果字母可以是任何 Unicode 字母,您可以使用这个正则表达式:

(?=.*?\p{Ll})(?=.*?\p{Lu})(?=.*?\d)(?=.*?[#&*%])^\S*$

要添加特殊字符,只需将它们放在 []

Use this:

(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[#&*%])^\S*$

If letter may be any Unicode letter, you can use this regex:

(?=.*?\p{Ll})(?=.*?\p{Lu})(?=.*?\d)(?=.*?[#&*%])^\S*$

To add special characters, simply put them inside []

神回复 2024-11-26 17:21:08

尝试一下

^.*(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

try that

^.*(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文