1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

link > Python > 文字列操作 > ファイル名として無効な文字を削除 (別解法: a whitelist approach) + 使用例 (at ideone in Python 3.5)

Last updated at Posted at 2019-01-28

文字列から「ファイル名無効文字」を省く処理。
re.sub()を使った実装例を紹介されている。

関数などで簡単に「無効文字」が取得できないか?

関数ではないが、自作関数で「無効文字」を削除している例は見つかった。

ホワイトリストアプローチ
string.ascii_lettersまたはstring.digitsのみを妥当な文字としての処理

これが有効かは使用者のやりたいことによるだろう

注記: seanhによる実装では「空白」を「_」に変換もしている

ideone使用例

ideone(Python3.5)で使用してみた
https://ideone.com/BMRVGl

関連

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?