我有一个字符串,我想提取的一个子集。这是一个更大的Python脚本的一部分。Python +正则表达式:AttributeError:'NoneType'对象没有属性'组'
这是字符串:
import re
htmlString = '</dd><dt> Fine, thank you. </dt><dd> Molt bé, gràcies. (<i>mohl behh, GRAH-syuhs</i>)'
,我要拔出 “蜕皮是gràcies莫尔behh,GRAH-syuhs”。为此,我用使用re.search
正则表达式:
SearchStr = '(\<\/dd\>\<dt\>)+ ([\w+\,\.\s]+)([\&\#\d\;]+)(\<\/dt\>\<dd\>)+ ([\w\,\s\w\s\w\?\!\.]+) (\(\<i\>)([\w\s\,\-]+)(\<\/i\>\))'
Result = re.search(SearchStr, htmlString)
print Result.groups()
AttributeError: 'NoneType' object has no attribute 'groups'
由于Result.groups()
不工作,我也不想让提取(即Result.group(5)
和Result.group(7)
)。 但我不明白为什么我会得到这个错误?正则表达式在TextWrangler中工作,为什么不在Python中?我是一个Python初学者。
尝试将您的'htmlString'解码为Unicode – thkang 2013-03-05 20:18:32