LoginSignup
21
16

More than 5 years have passed since last update.

pythonで文字列から数字だけ取り出す

Posted at
>>> import re
>>> re.sub(r'\D', '', "小林武(54歳)")
'54'

検索するとmatchオブジェクトを使うのが出てきますが
雑でいい時はこれでもいいと思います

21
16
1

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
21
16