Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于java正则表达式_Java_Regex - Fatal编程技术网

关于java正则表达式

关于java正则表达式,java,regex,Java,Regex,我想用以下条件编写正则表达式: 最少8个,最多64个字符 必须有1个字符和1个数字 允许使用特殊字符!@#$%^&*;:{}[] 你能帮忙吗 下面是我尝试过的表达方式 ((?=.*\d)(?=.[a-z])(?=.[a-z])(?=.[!@$%^&*:{}[\]])。{8,64}) 执行此操作的标准方法是使用正向lookaheads来断言字符和数字的存在: ^(?=[^A-Za-z]*[A-Za-z])(?=\D*\d)[A-Za-z0-9!@#$%^&*.;:{}\[\]]{8,64}

我想用以下条件编写正则表达式:

  • 最少8个,最多64个字符
  • 必须有1个字符和1个数字
  • 允许使用特殊字符!@#$%^&*;:{}[]
  • 你能帮忙吗

    下面是我尝试过的表达方式

    ((?=.*\d)(?=.[a-z])(?=.[a-z])(?=.[!@$%^&*:{}[\]])。{8,64})
    
    执行此操作的标准方法是使用正向lookaheads来断言字符和数字的存在:

    ^(?=[^A-Za-z]*[A-Za-z])(?=\D*\d)[A-Za-z0-9!@#$%^&*.;:{}\[\]]{8,64}$
    

    这种模式表明:

    ^                                       from the start of the password
        (?=[^A-Za-z]*[A-Za-z])              assert that a single character appears
        (?=\D*\d)                           assert that a single digit appears
        [A-Za-z0-9!@#$%^&*.;:{}\[\]]{8,64}  then match 8-64 valid characters
                                            (letters, numbers, special characters)
    $                                       end of password
    

    不要使用正则表达式。这看起来像是一个密码策略-停止使用。@luk2302那么你想让我用什么?@ManjuShankar我对密码策略本身没有问题,但你可能想让它比这更强大一点。目前,密码
    A1234567
    将通过检查(有多少人在他们的行李上使用此密码?。@ManjuShankar将这些条件分离到他们自己的测试中,以便您可以提供密码错误原因的反馈(我并不同意这些要求)而不是“无效密码”。@ ManjuShankar如果这个答案解决了你的问题,那么请考虑接受它,点击左边的绿色复选标记。