首页 > 编程语言 > 详细

python中正则提取日常积累

时间:2021-05-10 10:43:35      阅读:19      评论:0      收藏:0      [点我收藏+]

示例一:

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

  

 

python中正则提取日常积累

原文:https://www.cnblogs.com/tianpin/p/14749739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!