次の要件にRegEx(またはPythonの何か他のもの)を使用するにはどうすればよいですか? 私がする必要がある:文字列を置き換えるPython RegEx
- は、以前のすべての単語(単語「夢」の背後にある、すなわちすべての単語)
- の横にWordを削除ワード(そのすべての茎を含む)、「夢」
- を削除します(その前に/「夢」の右側に)
- すべてのフレーズから単語「to」を削除します。
入力:
text = ["Dream of a car",
"Dream to live in a world",
"Dream about 8am every morning",
"stopped dreaming today",
"still dreaming of a car",
"One more dream to come late tomorrow",
"Dream coming to hope tomorrow"]
必要な出力:
["a car",
"live in a world",
"8am every morning",
" ",
"a car",
"come late tomorrow",
"hope tomorrow"]
は、私が試した:
result = [re.sub('Dream', '', a) for a in text]
# MyOutput
[' of a car', ' to live in a world', ' about 8am every morning', 'stopped dreaming today', 'still dreaming of a car', 'One more dream to come late tomorrow', ' coming to hope tomorrow']
でにあなたがあなたの最初の要件の半分をやるだけでした提案するソリューションを削除したい場合は、とさえ*試み*休憩に対処するためのものではありません。 – jonrsharpe
はい私は残りの部分についてどうやって行くのか分かりません:( –
あなたの主張する出力はあなたの入力と一致しません。 – jonrsharpe