开发者

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

开发者 https://www.devze.com 2022-12-21 21:50 出处:网络
text = urllib.ur开发者_Go百科lopen(\'www.text.com\').read() frase = re.search(\"your text here(.*)\", text).group()
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

精彩评论

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