使用re.sub进行字符串替换
提取输入字符串中的数字
import re
option=input("")
option_str=re.sub("\D","",option) #\D匹配非数字字符
print(option_str)
运行结果:
生活1生活2
12
使用re.sub进行字符串替换
提取输入字符串中的数字
import re
option=input("")
option_str=re.sub("\D","",option) #\D匹配非数字字符
print(option_str)
运行结果:
生活1生活2
12