开发者

How can I remove part of an string on the re.search result?

text = urllib.ur开发者_Go百科lopen('www.text.com').read()
frase = re.search("your text here(.*)", text).group()

With these code, I get the result as "your text here mister"...

How can I remove the your text here from the result, staying only with the "mister" part?


Specify the number of the group (= thing between parenthesis in the regex) you want to receive in the call to group():

frase = re.search(...).group(1)


don't need regex

text = urllib.urlopen('www.text.com').read()
print ''.join( text.split("your text here")[1:] )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜