标志位对匹配过程做了一些限制.

标志位都是 re 模块内部已经预先定义好的常量

python3注意提供了以下几个标志位, 如果需要同时使用多个标志位, 使用 | 来实现.

标志位 说明
re.A或 re.ASCII 仅执行8位 ASCII 匹配 (python3开始支持)
re.I 或 re.IGNORECASE 匹配的时候忽略大小写
re.M或re.MULTILINE ^和$执行多行匹配. (对^和$来说, 默认是只匹配字符串的开始和结尾)
re.S 或 re.DOTALL 让点(.)匹配任意字符, 也包含换行符
re.X或re.VERBOSE 忽略模式字符串中未转义的空格和注释
a = re.compile(r"""\d +  # the integral part
                   \.    # the decimal point
                   \d *  # some fractional digits""", re.X)
b = re.compile(r"\d+\.\d*")
Copyright © 李振超 2018 all right reserved,powered by Gitbook
该文件最后修订时间: 2018-02-25 07:12:09

results matching ""

    No results matching ""