需要正则表达式的帮助 [英] need help with regex

查看:103
本文介绍了需要正则表达式的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要:

- 12-15个字符

- 包含至少1个大写字母或1个特殊字符

- 至少包含1个小写字母

- 包含至少1个数字



这是我到目前为止所获得的正则表达式,但仍未完成。

 ^(?= ^。{ 12 ,} $)((?=。* \ d)|??!(= * \W +))()(= * [AZ])(= * [AZ])* $ 
。]。?。 >

解决方案

)((?=。* \ d)|(?=。* \ W +))(?![。\ n]) (?=。* [AZ])(?=。* [AZ])*


唐不使用正则表达式 - 它不是文本匹配任务。

而是使用代码 - 一定要使用一堆不同的正则表达式(甚至一个正则表达式将字符分组到它们的类型中)但是在代码中检查数字等等 - 它更容易编写,并且更容易理解和维护。



执行此操作的正则表达式非常难以理解 - 与等效代码不同。


i need:
- 12-15 characters
- contain at least 1 capital letter OR 1 special character
- contain at least 1 small letter
- contain at least 1 number

this is the regex i get so far, but still not complete yet.

^(?=^.{12,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$

解决方案

)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*



Don't use a regex - it's not a "text matching" task.
Instead use code - by all means use a bunch of different regexes (or even a single regex to group the characters into their types) but check number and so forth in code - it's easier to wrote, and a lot easier to understand and maintain.

A regex to do that would be horribly difficult to understand - unlike the equivalent code.


这篇关于需要正则表达式的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆