我有一個字符串,我想提取的一個子集。這是一個更大的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