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

669 B
Raw Permalink Blame History

+++ date = '2025-08-10T12:37:16Z' title = '正则' +++

原子组

不回溯

(?>...)

占有量词

不回溯

.*+
.++
.?+

详细模式Verbose Mode / Free-Spacing Mode

regex_verbose = r"""
    ^                   # 匹配字符串开头
    (\d{4})             # 捕获四位数的年份
    -                   # 匹配连字符
    (\d{2})             # 捕获两位数的月份
    -                   # 匹配连字符
    (\d{2})             # 捕获两位数的日期
    $                   # 匹配字符串结尾
"""

date_string = "2023-10-26"
match = re.match(regex_verbose, date_string, re.VERBOSE)