mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-31 23:51:28 +08:00
💡 update regex docstring
This commit is contained in:
parent
59a8bd8c97
commit
47f491039c
@ -234,7 +234,9 @@ def command(command: Tuple[str, ...]) -> Rule:
|
|||||||
def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
|
def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
|
||||||
"""
|
"""
|
||||||
:说明:
|
:说明:
|
||||||
根据正则表达式进行匹配
|
根据正则表达式进行匹配。
|
||||||
|
|
||||||
|
可以通过 ``state["matched"]`` 获取正则表达式匹配成功的文本。
|
||||||
:参数:
|
:参数:
|
||||||
* ``regex: str``: 正则表达式
|
* ``regex: str``: 正则表达式
|
||||||
* ``flags: Union[int, re.RegexFlag]``: 正则标志
|
* ``flags: Union[int, re.RegexFlag]``: 正则标志
|
||||||
@ -247,9 +249,9 @@ def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
|
|||||||
pattern = re.compile(regex, flags)
|
pattern = re.compile(regex, flags)
|
||||||
|
|
||||||
async def _regex(bot: Bot, event: Event, state: dict) -> bool:
|
async def _regex(bot: Bot, event: Event, state: dict) -> bool:
|
||||||
matched_string = pattern.search(str(event.message))
|
matched = pattern.search(str(event.message))
|
||||||
if matched_string:
|
if matched:
|
||||||
state["matched_string"] = matched_string.group()
|
state["matched"] = matched.group()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user