LoginSignup
2
3

More than 3 years have passed since last update.

Pythonで正規表現を使ってASCII以外を置換する

Last updated at Posted at 2020-09-26

この記事ではPython3を使っています。

コード

test.py
import re

text = '''挫折を経験した事がない者は、
A何も新しい事に0 1挑戦したことが無いということだ。
ヲabc123!=*Z
- アルベルト・アインシュタイン -'''
after = re.sub('[^!-~\\s]|[ ]', '○', text)

print (after)

実行結果

○○○○○○○○○○○○○○
○○○○○○○○0 1○○○○○○○○○○○○○○○○
○abc123!=*○
-○○○○○○○○○○○○○○○○-

参考

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3