• <legend id='g4m2c'><style id='g4m2c'><dir id='g4m2c'><q id='g4m2c'></q></dir></style></legend>

      <small id='g4m2c'></small><noframes id='g4m2c'>

      1. <tfoot id='g4m2c'></tfoot>

          <bdo id='g4m2c'></bdo><ul id='g4m2c'></ul>

      2. <i id='g4m2c'><tr id='g4m2c'><dt id='g4m2c'><q id='g4m2c'><span id='g4m2c'><b id='g4m2c'><form id='g4m2c'><ins id='g4m2c'></ins><ul id='g4m2c'></ul><sub id='g4m2c'></sub></form><legend id='g4m2c'></legend><bdo id='g4m2c'><pre id='g4m2c'><center id='g4m2c'></center></pre></bdo></b><th id='g4m2c'></th></span></q></dt></tr></i><div id='g4m2c'><tfoot id='g4m2c'></tfoot><dl id='g4m2c'><fieldset id='g4m2c'></fieldset></dl></div>

        如何在 Python 中测试正则表达式密码?

        How to test a regex password in Python?(如何在 Python 中测试正则表达式密码?)
          <legend id='ciJLr'><style id='ciJLr'><dir id='ciJLr'><q id='ciJLr'></q></dir></style></legend>
        • <i id='ciJLr'><tr id='ciJLr'><dt id='ciJLr'><q id='ciJLr'><span id='ciJLr'><b id='ciJLr'><form id='ciJLr'><ins id='ciJLr'></ins><ul id='ciJLr'></ul><sub id='ciJLr'></sub></form><legend id='ciJLr'></legend><bdo id='ciJLr'><pre id='ciJLr'><center id='ciJLr'></center></pre></bdo></b><th id='ciJLr'></th></span></q></dt></tr></i><div id='ciJLr'><tfoot id='ciJLr'></tfoot><dl id='ciJLr'><fieldset id='ciJLr'></fieldset></dl></div>

              <tbody id='ciJLr'></tbody>
            <tfoot id='ciJLr'></tfoot>

            <small id='ciJLr'></small><noframes id='ciJLr'>

                <bdo id='ciJLr'></bdo><ul id='ciJLr'></ul>
                1. 本文介绍了如何在 Python 中测试正则表达式密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Python 中使用正则表达式,我如何验证用户的密码是:

                  Using a regex in Python, how can I verify that a user's password is:

                  • 至少 8 个字符
                  • 必须限于,但不具体要求:
                    • 大写字母:A-Z
                    • 小写字母:a-z
                    • 数字:0-9
                    • 任何特殊字符:@#$%^&+=

                    注意,所有字母/数字/特殊字符都是可选的.我只想验证密码长度是否至少为 8 个字符,并且仅限于字母/数字/特殊字符.如果他们愿意,用户可以选择更强/更弱的密码.到目前为止,我所拥有的是:

                    Note, all the letter/number/special chars are optional. I only want to verify that the password is at least 8 chars in length and is restricted to a letter/number/special char. It's up to the user to pick a stronger / weaker password if they so choose. So far what I have is:

                    import re
                    pattern = "^.*(?=.{8,})(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$"
                    password = raw_input("Enter string to test: ")
                    result = re.findall(pattern, password)
                    if (result):
                        print "Valid password"
                    else:
                        print "Password not valid"
                    

                    推荐答案

                    import re
                    password = raw_input("Enter string to test: ")
                    if re.fullmatch(r'[A-Za-z0-9@#$%^&+=]{8,}', password):
                        # match
                    else:
                        # no match
                    

                    {8,} 表示至少 8 个"..fullmatch 函数要求整个字符串匹配整个正则表达式,而不仅仅是一部分.

                    The {8,} means "at least 8". The .fullmatch function requires the entire string to match the entire regex, not just a portion.

                    这篇关于如何在 Python 中测试正则表达式密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                  • <small id='i7qp5'></small><noframes id='i7qp5'>

                  • <i id='i7qp5'><tr id='i7qp5'><dt id='i7qp5'><q id='i7qp5'><span id='i7qp5'><b id='i7qp5'><form id='i7qp5'><ins id='i7qp5'></ins><ul id='i7qp5'></ul><sub id='i7qp5'></sub></form><legend id='i7qp5'></legend><bdo id='i7qp5'><pre id='i7qp5'><center id='i7qp5'></center></pre></bdo></b><th id='i7qp5'></th></span></q></dt></tr></i><div id='i7qp5'><tfoot id='i7qp5'></tfoot><dl id='i7qp5'><fieldset id='i7qp5'></fieldset></dl></div>

                    <tfoot id='i7qp5'></tfoot><legend id='i7qp5'><style id='i7qp5'><dir id='i7qp5'><q id='i7qp5'></q></dir></style></legend>
                      • <bdo id='i7qp5'></bdo><ul id='i7qp5'></ul>

                            <tbody id='i7qp5'></tbody>