美文网首页测试那些事儿Python基础
python匹配特定字符中间的数据

python匹配特定字符中间的数据

作者: 极客与宽客 | 来源:发表于2019-03-06 16:37 被阅读12次

import re

string ='万科A(000002):万科2018年'

p1 = re.compile(r'[<em>](.*?)[</em>]', re.S)#最小匹配

p2 = re.compile(r'[<em>](.*)[</em>]', re.S)#贪婪匹配

print(re.findall(p1, string))

print(re.findall(p2, string))

结果:

['', '', '', '', 'A(', '', '000002', '', '):', '', '万科', '']

['em>万科</em>A(<em>000002</em>):<em>万科</em']

相关文章

网友评论

    本文标题:python匹配特定字符中间的数据

    本文链接:https://www.haomeiwen.com/subject/wblxpqtx.html