# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nining.website/python/func/builtin-module/re.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
