私は次のテスト文字列を持っています:
test_str = `It isn't directed at all,' said the White Rabbit;
現在の正規表現ではre.sub
、句読点を除外して、独自の操作を実行できるようにしています。
私の現在の正規表現は re.sub(r"[^A-Za-z0-9'\s]", '', test_str)
上からの出力は次のとおりです。
['It', "isn't", 'directed', 'at', "all'", 'said', 'the', 'White', 'Rabbit']
エラーall'
は、保存all
のみを想定している場合に見られます。
句読点の後に来る単語をどのように保存し's
、無視'
しますか?この場合、all,'
。
次のことを試してください。
import re
test_str = "`It isn't directed at all,' said the White Rabbit;"
a = re.sub(r"[^A-Za-z0-9'\s]", '', test_str)
a = re.sub(r"'[ ]", ' ', a)
print(a)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加