示例一:
import re
strTest = '美通卡支付9.5折'
contentValue = re.findall(r"\d+\.?\d*", strTest)
print(contentValue) ['9.5']
print(type(contentValue)) <class 'list'>
contentValueNew = re.findall(r"\d+\.?\d*", strTest)[0]
print(contentValueNew) 9.5
print(type(contentValueNew)) <class 'str'>
示例二:
使用正则提取括号的内容,代码如下
strTest = 'Major (一般)'
priorityRe =re.findall(r'[(](.*?)[)]',strTest)
print(priorityRe) ['一般']
priorityRe2 =re.findall(r'[(](.*?)[)]',strTest)[0]
print(priorityRe2) 一般