Python 中是否有与 Regexp.last_match(1) 等效的函数?

问题描述 投票:0回答:1

在 Ruby 中,可以使用“Regexp.last_match(index_of_subgroup)”来引用最后一个匹配 RegExp 的子组,而无需知道保存匹配 RegExp 的变量。

我想避免在 python 中使用类似 VarName.group(1) 的东西,因为我不一定知道给定的 RegExp 匹配 Varname 是什么。

Python 中有等价的东西吗?

python regex
1个回答
0
投票

您可以使用 re 模块和 re.lastindex 属性以及 re.group() 方法。

© www.soinside.com 2019 - 2024. All rights reserved.