Python 字符串查找数字

Python 字符串查找数字

import re

str = 'abc123cd45'
ret1 = re.search('\d+', str).group()
ret2 = re.findall('\d+', str)

print(ret1)  # 输出:123
print(ret2)  # 输出:['123', '45']

你可能感兴趣的:(python)