私はサブセットを抽出したい文字列を持っています。これは、より大きなPythonスクリプトの一部です。Python + Regex:AttributeError: 'NoneType'オブジェクトに 'groups'属性がありません。
これは文字列です "モルトBéを、gràciesmohl behh、GRAH-syuhs"
import re
htmlString = '</dd><dt> Fine, thank you. </dt><dd> Molt bé, gràcies. (<i>mohl behh, GRAH-syuhs</i>)'
私はアウトを引き出したいです。そして、そのために、私はre.search
を使用して、正規表現を使用しない:Result.groups()
以来
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.group(5)
とResult.group(7)
)を行います。 しかし、なぜこのエラーが出るのか分かりません。正規表現はTextWranglerで動作しますが、なぜPythonでは使えませんか?私はPythonの初心者です。
'htmlString'をUnicodeにデコードしようとしています – thkang