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())

 

posted @ 2018-12-01 13:48  coffee~  阅读(740)  评论(0编辑  收藏  举报