python - 组合重新标记 re.IGNORECASE、re.MULTILINE 和 re.DOTALL

标签 python python-3.x re

谁能告诉我是否可以组合像 re.IGNORECASE 这样的标志, re.MULTILINEre.DOTALL正则表达式匹配?

r = re.compile(regex, re.IGNORECASE | re.MULTILINE | re.DOTALL)
我需要根据用例在一行中匹配整个段落或表达式。

最佳答案

是的,您可以将正则表达式标志与 | 结合使用.
文档 https://docs.python.org/3/library/re.html#re.compile具体说:

The expression’s behaviour can be modified by specifying a flags value. Values can be any of the following variables, combined using bitwise OR (the | operator).

关于python - 组合重新标记 re.IGNORECASE、re.MULTILINE 和 re.DOTALL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66139972/

相关文章:

python - pygtk 中 connect() 和 connect_object() 的区别

python - 是否可以将 django View 集与两个序列化器一起使用?

python - Pytest - 使用 asyncio 进行 python 测试

python - 从 next_sibling 获取文本 - BeautifulSoup 4

python - 修复句子 : add space after punctuation but not after decimal points or abbreviations

python - 无法使用请求从网页中获取所有链接

python - 如何匹配格式 “Sep-14” 将其转换为 DATETIME

python - Django 运行余额/累计余额

python-3.x - 如何在 Python 3 中使用 lxml?

python - CalledProcessError : Command '[' pdftotext', '-layout' , 'coburns.pdf' , '-' ]' returned non-zero exit status 1?