【python】特定模式抽取字符串

来源:互联网 发布:淘宝怎么推广宝贝 编辑:程序博客网 时间:2024/05/22 11:40

环境:win7 + python3.5.2

问题描述:希望从“<边界>string<边界>“模式中将string抽取出来

import rep = re.compile(r'\<polarity\>(.*)\</polarity\>')matchp = p.search("<polarity>positive</polarity>") if matchp in not None:     print(matchp.group(1))#消耗边界    print(matchp.group(0))#不消耗边界

运行结果:

positive<polarity>positive</polarity>
0 0
原创粉丝点击