使用regex python提取子字符串

2024-10-01 09:27:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道这是一个经常被问到的问题,但它快把我逼疯了。在

我想使用正则表达式来匹配字符串中的子字符串。在

 line = '##ParameterValue[part I care about]=garbagegarbage'

我想提取part I care about。 我的代码如下:

^{pr2}$

但这给了我一个AttributeError: 'NoneType' object has no attribute 'group'

我在regex101上测试了我的regex,它工作了。我不明白为什么这对我来说失败了。在


Tags: no字符串代码objectlineattributeaboutattributeerror