0
我知道这是一个非常常见的问题,但它让我很生气。用正则表达式提取子字符串python
我想使用正则表达式匹配我的字符串中的子字符串。
line = '##ParameterValue[part I care about]=garbagegarbage'
我想提取part I care about
。 我的代码如下所示:
import re
line = '##ParameterValue[part I care about]=garbagegarbage'
m = re.match('\[(.*)\]', line)
print m.group(1)
但是这给了我一个AttributeError: 'NoneType' object has no attribute 'group'
我测试了我的正则表达式上regex101和它的作品。我不明白为什么这对我不合适。
你是对的,这是过于频繁的问题。 –
尝试['search'](https://docs.python.org/2/library/re.html#re.search)。 ['match'](https://docs.python.org/2/library/re.html#re.match)正在寻找匹配从字符串的开头。 –