37,700
社区成员




#python 3.2
#coding=gb2312
import re
content = "motorola--"
print(re.search(r'mot(?:orola)?--', content, re.I).group())
content = "mot--"
print(re.search(r'mot(?:orola)?--', content, re.I).group())
[Quote=引用 2 楼 的回复:]import re
content = "motorola--"
print(re.findall(r'mot(?:orola)?--', content, re.I))
content = "mot--"
print(re.findall(r'mot(?:orola)?--', content, re.I))
['motorola--']
['mot--']
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import re
>>> text = ['moto--', 'motorola--']
>>> for l in text:
mat = re.search(r'moto.*?--', l)
if mat:
print mat.group()
moto--
motorola--
>>>