1
0
Files
cheatsheet-site/content/util/regex.md
yuudi 728a3db957
Some checks failed
Build / build (push) Has been cancelled
init
2025-08-12 18:37:54 -06:00

40 lines
669 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

+++
date = '2025-08-10T12:37:16Z'
title = '正则'
+++
## 原子组
不回溯
```regex
(?>...)
```
## 占有量词
不回溯
```regex
.*+
.++
.?+
```
## 详细模式Verbose Mode / Free-Spacing Mode
```python
regex_verbose = r"""
^ # 匹配字符串开头
(\d{4}) # 捕获四位数的年份
- # 匹配连字符
(\d{2}) # 捕获两位数的月份
- # 匹配连字符
(\d{2}) # 捕获两位数的日期
$ # 匹配字符串结尾
"""
date_string = "2023-10-26"
match = re.match(regex_verbose, date_string, re.VERBOSE)
```