Here is the code I have so far:

import re
from urllib.request import urlopen

pg = urlopen('http://www.url.com')
pg_r = pg.read()
pg.close()
print(pg_r)
print(re.search('(?<=http://user.url.com/)\w+', pg_r))

What I *want* to do with re.search is find the word between the strings 'http://user.url.com/' and '"' but I'm not sure how to do that..
Can anyone help me with the regular expression for that?

re.search() returns a MatchObejct, not the string that matches the regex.
Look up in the docs what you can do with it to get the match string.

A better regex to use is

matchObj = re.search('(?<=http://user.url.com/)[^"]+', pg_r)
if matchObj:
    pass # found a match
commented: Thanks for helping me with regular expressions! o.o +1

Thank you so much! Problem solved. Also, thanks for the insight into what type is returned.

Also in Python3 'pg_r' would be a byte string and module re will complain without converting 'pg_r' to a string first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.