MCPcopy
hub / github.com/nonebot/nonebot2 / regex

Function regex

nonebot/rule.py:696–717  ·  view source on GitHub ↗

匹配符合正则表达式的消息字符串。 可以通过 {ref}`nonebot.params.RegexStr` 获取匹配成功的字符串, 通过 {ref}`nonebot.params.RegexGroup` 获取匹配成功的 group 元组, 通过 {ref}`nonebot.params.RegexDict` 获取匹配成功的 group 字典。 参数: regex: 正则表达式 flags: 正则表达式标记 :::tip 提示 正则表达式匹配使用 search 而非 match,如需从头匹配请使用 `r"^xxx

(regex: str, flags: int | re.RegexFlag = 0)

Source from the content-addressed store, hash-verified

694
695
696def regex(regex: str, flags: int | re.RegexFlag = 0) -> Rule:
697 """匹配符合正则表达式的消息字符串。
698
699 可以通过 {ref}`nonebot.params.RegexStr` 获取匹配成功的字符串,
700 通过 {ref}`nonebot.params.RegexGroup` 获取匹配成功的 group 元组,
701 通过 {ref}`nonebot.params.RegexDict` 获取匹配成功的 group 字典。
702
703 参数:
704 regex: 正则表达式
705 flags: 正则表达式标记
706
707 :::tip 提示
708 正则表达式匹配使用 search 而非 match,如需从头匹配请使用 `r"^xxx"` 来确保匹配开头
709 :::
710
711 :::tip 提示
712 正则表达式匹配使用 `EventMessage` 的 `str` 字符串,
713 而非 `EventMessage` 的 `PlainText` 纯文本字符串
714 :::
715 """
716
717 return Rule(RegexRule(regex, flags))
718
719
720class ToMeRule:

Callers 2

on_regexFunction · 0.90
test_regexFunction · 0.90

Calls 2

RuleClass · 0.90
RegexRuleClass · 0.85

Tested by 1

test_regexFunction · 0.72