在wtforms
的文档中是这样解释的:
表示没有看懂,请各位大神指点。主要疑惑在:
for example re.IGNORECASE
是什么意思,难道这个参数还等代表re
模块中的其它常量?
Ignored if regex is not a string.
我觉得regex
这个参数只能是string
类型吧?还会有其它的情况嘛?
阿神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
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 theflags
参数在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
is not a string, then there is no compilation step, so these parameters will naturally be ignored. regex