python中正则提取日常积累

示例一:

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)  一般

  

 

posted @ 2021-05-10 09:22  我是一只小小小小鸟~  阅读(75)  评论(0编辑  收藏  举报