2010-08-02 64 views

回答

3

可能做到这一点,并寻找*,但正则表达式的工作。

print re.search(r'\*\*(.*)\*\*', 'hello **world**').group(1) # prints 'world' 

你需要知道究竟你在找什么用正则表达式,所以想想**asd**dfe**和类似的边缘情况应该返回。

1
import re 
print re.findall(r"\*\*(.*)\*\*", row[2]) 

会给你row[2]每场比赛这是**之间的列表。微调必要的正则表达式

0

行[2] .strip(“*”)

不要使用电锯时,一把刀就行了。

+0

>>>行[2 ] .strip('*') 'hello ** world' – 2010-08-02 19:17:29

+0

呵呵?你怎么知道哪个部分是'**'之间的部分? – 2010-08-02 19:18:17

+0

oops,解析我的错误,谢谢。 – msw 2010-08-02 19:18:32

1

比方说,你不知道哪个元素有星星,你可以这样做:

row=['alex','liza','hello **world**','blah'] 
for staritem in (item for item in row if '**' in item): 
    print(staritem) 
    _,_, staritem = staritem.partition('**') 
    staritem,_,_ = staritem.partition('**') 
    print(staritem)