Python正则表达式匹配数字和小数

1、匹配数字

import re

str_date = 'hello world today is 2022.4.15 ok'
num_list = re.findall('\d+', str_date)
print('匹配到的数字', num_list)

输出:

匹配到的数字 ['2022', '4', '15']

2、匹配数字、小数点

更多推荐

Python正则表达式匹配数字和小数