词匹配^ . *(? = . * \ \ d)(? =。*[a-zA-Z])(? =。*[! @ # $ % ^ &])。*美元

时间:2021-12-11 21:20:08

I am totally confused right now.

我现在完全糊涂了。

What is a word that matches: ^.*(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$

什么是词相匹配:^ . *(? = . * \ \ d)(? =。*[a-zA-Z])(? =。*[! @ # $ % ^ &])。* $

I tried at Regex 101 this 1Test@!. However that does not work.

我尝试了Regex 101这个1Test@!然而,这并不奏效。

I really appreciate your input!

非常感谢你的投入!

4 个解决方案

#1


3  

What happens is that your regex seems to be in Java-flavor (Note the \\d)

你的正则表达式似乎是在java风格中(注意\\d)

that is why you have to convert it to work with regex101 which does not work with jave (only works with php, phyton, javascript)

这就是为什么要将它转换为与regex101一起工作的原因,而regex101与jave不兼容(只适用于php、phyton、javascript)

see converted regex:

看到转换正则表达式:

 ^.*(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$

which will match your string 1Test@!. Demo here: http://regex101.com/r/gE3iQ9

这将匹配您的字符串1Test@!演示:http://regex101.com/r/gE3iQ9

#2


1  

You just want something that matches that regex?

你只是想要一些和正则表达式匹配的东西?

Here:

在这里:

a1a!

#3


1  

This pattern matches

这种模式匹配

\dTest@!

\ dTest@ !

if u want a pattern which matches 1Test@! try this pattern

如果您想要一个匹配1Test@的模式!试试这个模式

^.(?=.\d)(?=.[a-zA-Z])(?=.[!@#$%^&]).*$

(? = ^。\ d)(? =。[a-zA-Z])(? =。[! @ # $ % ^ &])。*美元

#4


1  

Your java string ^.*(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$ encodes the regexp expression ^.*(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$.

您的java字符串^。*(? = . * \ \ d)(? =。*[a-zA-Z])(? =。*[! @ # $ % ^ &])。* ^ $编码regexp表达式。*(? = . * \ d)(? =。*[a-zA-Z])(? =。*[! @ # $ % ^ &])。*美元。

This is because the \ is an escape sequence.

这是因为\是一个转义序列。

The latter matches the string you specified.

后者匹配您指定的字符串。

If your original string was a regexp, rather than a java string, it would match strings such as \dTest@!

如果您的原始字符串是regexp,而不是java字符串,那么它将匹配字符串,比如\dTest@!

Also you should consider removing the first .*, doing so would make the regexp more efficient. The reason is that regexp's by default are greedy. So it will start by matching the whole string to the initial .*, the lookahead will then fail. The regexp will backtrack, matchine the first .* to all but the last character, and will fail all but one of the loohaheads. This will proceed until it hits a point where the different lookaheads succeed. Dropping the first .*, putting the lookahead immidiately after the start of string anchor, will avoid this problem, and in this case the set of strings matched will be the same.

此外,您应该考虑删除第一个。*,这样做会使regexp更有效。原因是regexp默认是贪婪的。因此,它将首先匹配整个字符串到初始值。regexp将会回溯,matchine第一个。*除了最后一个角色,而且将会失败除了一个loohaheads。这将继续下去,直到它达到一个不同的lookahead成功的点。删除第一个。*,在字符串锚开始后,将lookahead放在前面,将避免这个问题,在这种情况下,匹配的字符串集将是相同的。

#1


3  

What happens is that your regex seems to be in Java-flavor (Note the \\d)

你的正则表达式似乎是在java风格中(注意\\d)

that is why you have to convert it to work with regex101 which does not work with jave (only works with php, phyton, javascript)

这就是为什么要将它转换为与regex101一起工作的原因,而regex101与jave不兼容(只适用于php、phyton、javascript)

see converted regex:

看到转换正则表达式:

 ^.*(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$

which will match your string 1Test@!. Demo here: http://regex101.com/r/gE3iQ9

这将匹配您的字符串1Test@!演示:http://regex101.com/r/gE3iQ9

#2


1  

You just want something that matches that regex?

你只是想要一些和正则表达式匹配的东西?

Here:

在这里:

a1a!

#3


1  

This pattern matches

这种模式匹配

\dTest@!

\ dTest@ !

if u want a pattern which matches 1Test@! try this pattern

如果您想要一个匹配1Test@的模式!试试这个模式

^.(?=.\d)(?=.[a-zA-Z])(?=.[!@#$%^&]).*$

(? = ^。\ d)(? =。[a-zA-Z])(? =。[! @ # $ % ^ &])。*美元

#4


1  

Your java string ^.*(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$ encodes the regexp expression ^.*(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&]).*$.

您的java字符串^。*(? = . * \ \ d)(? =。*[a-zA-Z])(? =。*[! @ # $ % ^ &])。* ^ $编码regexp表达式。*(? = . * \ d)(? =。*[a-zA-Z])(? =。*[! @ # $ % ^ &])。*美元。

This is because the \ is an escape sequence.

这是因为\是一个转义序列。

The latter matches the string you specified.

后者匹配您指定的字符串。

If your original string was a regexp, rather than a java string, it would match strings such as \dTest@!

如果您的原始字符串是regexp,而不是java字符串,那么它将匹配字符串,比如\dTest@!

Also you should consider removing the first .*, doing so would make the regexp more efficient. The reason is that regexp's by default are greedy. So it will start by matching the whole string to the initial .*, the lookahead will then fail. The regexp will backtrack, matchine the first .* to all but the last character, and will fail all but one of the loohaheads. This will proceed until it hits a point where the different lookaheads succeed. Dropping the first .*, putting the lookahead immidiately after the start of string anchor, will avoid this problem, and in this case the set of strings matched will be the same.

此外,您应该考虑删除第一个。*,这样做会使regexp更有效。原因是regexp默认是贪婪的。因此,它将首先匹配整个字符串到初始值。regexp将会回溯,matchine第一个。*除了最后一个角色,而且将会失败除了一个loohaheads。这将继续下去,直到它达到一个不同的lookahead成功的点。删除第一个。*,在字符串锚开始后,将lookahead放在前面,将避免这个问题,在这种情况下,匹配的字符串集将是相同的。