python 文字列のドット以降の削除
正規表現を用いて削除してみる
以下サンプルコード。元文字 「test.xxx」のドット以降を削除する
import re st = "test.xxx" # 元の文字列 new_st = e.sub(r'\..+$', '',files[0]) # ドット以降削除 print(new_st) # 変換後の文字列の出力 # => test
正規表現を用いて削除してみる
以下サンプルコード。元文字 「test.xxx」のドット以降を削除する
import re st = "test.xxx" # 元の文字列 new_st = e.sub(r'\..+$', '',files[0]) # ドット以降削除 print(new_st) # 変換後の文字列の出力 # => test