tags:

views:

51

answers:

2
text = urllib.urlopen('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?

+3  A: 

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)
sth
and if I get something before the "mister", like, "mister wrong"... how do I remove the "wrong" ?
Shady
@Shady: Edit the regular expression so that it matches (only) the correct text and put the parenthesis around the part you are interested in.
sth
+1  A: 

don't need regex

text = urllib.urlopen('www.text.com').read()
print ''.join( text.split("your text here")[1:] )
ghostdog74
good, it works... but it transform string as list... how can I convert back?
Shady
to convert list back to string, use join().
ghostdog74