Regex 如何将两个正则表达式语句与AND组合?
我有两个regex语句,它们分别工作得很好 第一个正则表达式:Regex 如何将两个正则表达式语句与AND组合?,regex,Regex,我有两个regex语句,它们分别工作得很好 第一个正则表达式: ^(?=.*[\w].*) assert that what follows the start of the string includes one (or more) non symbol characters .{4,}$ match any character four or more times (.[\w].*)//这意味着测试至少包含一个非特殊字符 第二个正
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times
(.[\w].*)
//这意味着测试至少包含一个非特殊字符
第二个正则表达式:
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times
{3,}.
//文本大于3个字符
所以我想要两个组合这两个正则表达式。匹配大于3个字符且至少包含一个非特殊字符的文本
我的测试文本:
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times
asd
//不匹配
asd@
//匹配
@{{}{a
//匹配
@{}@{}
//不匹配
*/*/*/+
不匹配
5542
//匹配
@{}43
//match我不认为有一种将两个regexp相交的通用方法,但这一个可以重新表述为
- 非特殊字符,后跟三个字符,或
- 非特殊字符,前面有两个字符,或
- 非特殊字符,前跟两个字符,后跟一个字符,或
- 非特殊字符,前面有一个字符,后跟两个字符,或
- 非特殊字符,前面有e个字符
/.*\w...+|.+\w..+|.+.\w.+|...+\w.*/
(演示了一种更通用的方法来实现与AND非常类似的功能。)我认为没有一种通用的方法可以将两个regexp相交,但这一个可以重新表述为
- 非特殊字符,后跟三个字符,或
- 非特殊字符,前面有两个字符,或
- 非特殊字符,前跟两个字符,后跟一个字符,或
- 非特殊字符,前跟一个字符后跟两个字符,或
- 非特殊字符,前面有e个字符
/.*\w...+|.+\w..+|.+.\w.+|...+\w.*/
(演示了一种更通用的方法来实现与AND非常相似的功能。)实现这一功能的一种方法是使用正向前瞻断言非符号字符在模式中至少出现一次。然后匹配长度为4或更多的任何字符(已保证非符号字符存在的断言) 说明:
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times
此处演示:
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times
实现这一点的一种方法是使用正向前瞻断言非符号字符在模式中至少出现一次。然后匹配长度为四个或四个以上的任何字符(该断言已保证存在非符号字符) 说明:
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times
此处演示:
^(?=.*[\w].*) assert that what follows the start of the string
includes one (or more) non symbol characters
.{4,}$ match any character four or more times