admin管理员组

文章数量:1794759

python正则匹配

1. 匹配字符串中的一个百分比数字

import re

t = 'yuchen is a very lovely girl. 5.568% company ltd.'

match = re.search(r"\d+\.\d*%", t)

print(match.group())

2.匹配小括号()里面的内容

# 这种方式的输出是列表类型, 不包含括号本身

import re

t = '(123, "345")' match = re.findall( r"[(](.*)[)]",  t ) print(match)

3.匹配字符串中的一个数字

import re

t = '123 entity' match = re.search(r"\d+", t ) print(match.group())

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2018-12-01,如有侵权请联系 cloudcommunity@tencent 删除pythonimportmatchsearch字符串

本文标签: python正则匹配