Python正则表达式匹配数字和小数
1、匹配数字
import re
str_date = 'hello world today is 2022.4.15 ok'
num_list = re.findall('\d+', str_date)
print('匹配到的数字', num_list)
- 1
- 2
- 3
- 4
- 5
输出:
匹配到的数字 ['2022', '4', '15']
- 1
2、匹配数字、小数点
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']