私は RE にあまり詳しくありませんが、リストを反復処理してre.sub
、 variable に保持されている大きなテキスト ブロックから複数の項目を取り出すために使用しようとしていますfirst_word
。
最初にre.sub
タグを削除していましたが、これはうまくいきましたが、次にexclusionList
変数内のすべての文字列を削除したいのですが、これを行う方法がわかりません。
助けてくれてありがとう、これは例外を発生させるコードです。
exclusionList = ['+','of','<ET>f.','to','the','<L>L.</L>']
for a in range(0, len(exclusionList)):
first_word = re.sub(exclusionList[a], '',first_word)
そして例外:
first_word = re.sub(exclusionList[a], '',first_word)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 245, in _compile
raise error, v # invalid expression error: nothing to repeat