init
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
39
content/util/regex.md
Normal file
39
content/util/regex.md
Normal file
@@ -0,0 +1,39 @@
|
||||
+++
|
||||
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)
|
||||
```
|
||||
Reference in New Issue
Block a user