> For the complete documentation index, see [llms.txt](https://nining.website/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nining.website/python/func/builtin-module/re.md).

# re

在 Python 中，使用内置的 re 模块来使用正则表达式

> 注意点：\ 对特殊字符进行转义，比如'python.org' --> 'python\\.org'，而 Python 的字符串本身也用  \ 转义，所以应写成 'python\\\\.org'，很容易陷入困扰，直接r'python\\.org' 较好

re 模块的一般使用步骤：

* 使用 compile 函数将正则表达式的字符串形式编译为一个Pattern对象
* 通过Pattern对象提供的一系列方法对文本进行匹配查找，获得匹配结果(一个 Match 对象)
* 最后使用 Match 对象提供的属性和方法获得信息，根据需要进行其他操作

参考链接

1. &#x20;[re 模块](https://wiki.jikexueyuan.com/project/explore-python/Regular-Expressions/re.html)
