繁体   English   中英

Python 正则表达式模块:正则表达式实例中数字表示背后的标志是什么?

[英]Python regex module: what flag is behind a number representation in Regex instance?

默认使用哪些标志,即数字8224后面是什么? 是否有标志的数字表示列表?

>>> import regex
>>> compiled_pattern = regex.compile("/d+")
>>> compiled_pattern.flags
8224

它是一个位域,即每个位代表一个标志的存在。

>>> re.compile("/d+", re.IGNORECASE).flags
34

>>> re.RegexFlag(34)
re.IGNORECASE|re.UNICODE

>>> int(re.IGNORECASE) | int(re.UNICODE)
34

>>> {f: int(f) for f in re.RegexFlag}
{re.ASCII: 256, re.IGNORECASE: 2, re.LOCALE: 4, re.UNICODE: 32, re.MULTILINE: 8, re.DOTALL: 16, re.VERBOSE: 64, re.TEMPLATE: 1, re.DEBUG: 128}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM