我的问题是这样的,有一个字符串。
我需要一个包含以下内容的列表:
显然,通过逗号分隔无法达到效果,因此我们采用正则表达式分组。
我尝试的是匹配仅在逗号后出现空格和字母的情况,但对我来说,结果不正确。
[word in IN ('hello', 'world'), key1=1100, key2=1200]
我需要一个包含以下内容的列表:
[word in IN ('hello', 'world'),
key1=1100,
key2=1200
]
显然,通过逗号分隔无法达到效果,因此我们采用正则表达式分组。
pattern= re.compile(r"(.*), [a-zA-Z]?", re.DOTALL)
string = "[word in IN ('hello', 'world'), key1=1100, key2=1200]"
for item in re.findall(pattern, string):
print item
我尝试的是匹配仅在逗号后出现空格和字母的情况,但对我来说,结果不正确。
[word in IN ('hello', 'world'), key1=1100
然而,这是贪婪匹配。如果能提供帮助将不胜感激。