查找字符串【python】

bbsyuewu 发布于 2012/08/01 21:49
阅读 714
收藏 0

查找字符串:

emem中间任意emem

两端都是emem的字符串      Thank You!

加载中
0
PYPlus
PYPlus
In [1]: import re

In [2]: test=['emememem','ememlinux','ipythonemem','ipythonipython','ememipythonemem']

In [3]: restring='emem'

In [4]: re_obj=re.compile('^emem.*emem$')

In [5]: for i in test:
   ...:     if re_obj.search(i):
   ...:         print(i)
   ...:
emememem
ememipythonemem

In [6]:


0
wireshark
wireshark
有人看懂了吗?
岛
真心看不懂
0
少帮主
少帮主

用regex吧

import re

re.search('^emem\w*emem$', "ememxyzemem")

FYI:

 

http://docs.python.org/library/re.html

返回顶部
顶部