search

Home  >  Q&A  >  body text

python - wtforms.validators中的Regexp验证函数的flags参数有什么作用?

wtforms的文档中是这样解释的:

表示没有看懂,请各位大神指点。主要疑惑在:

  1. for example re.IGNORECASE是什么意思,难道这个参数还等代表re模块中的其它常量?

  2. Ignored if regex is not a string.我觉得regex这个参数只能是string类型吧?还会有其它的情况嘛?

大家讲道理大家讲道理2892 days ago752

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 18:01:08

    I have never used this library, but I will answer according to my own understanding of re. This should encapsulate some regular functions

    1. Reference https://docs.python.org/2/library/re.html#re.compile
    flags: View specific flag constants

    re.DEBUG
    re.I
    re.IGNORECASE
    re.L
    re.LOCALE
    re.M
    re.MULTILINE
    re.S
    re.DOTALL
    re.U
    re.UNICODE
    re.X
    re.VERBOSE

    2. What he means is that the value type passed in regex is not string, ignore it


    update:

    Download the library and see the source code at a glance:

    site-packages/wtforms/validators.py line 264

    def __init__(self, regex, flags=0, message=None):
        if isinstance(regex, string_types):
            regex = re.compile(regex, flags)
        self.regex = regex
        self.message = message

    First determine whether the incoming regx is a string, and then compile

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 18:01:08

    I don’t know why I can’t modify the question, so I’ll add an answer of my own and then synthesize the adopted answers.

    The documentation of the
    1. flags参数在re module is described like this:

    Values ​​can be any of the following variables, combined using bitwise OR (the | operator).

    These constants can be used simultaneously using the bit or the operator. The default value is 0, which means no flag constants are used, which makes sense. for example

    1. As shown in the source code, if

      is not a string, then there is no compilation step, so these parameters will naturally be ignored. regex

    2. reply
      0
  • Cancelreply