[Tutor] newbie re question

tpc@csua.berkeley.edu tpc@csua.berkeley.edu
Mon Jun 30 13:27:02 2003


hi Danny, I had a question about your quick intro to Python lesson
sheet you gave out back in March 2001.  The last page talks about
formulating a regular expression to handle URLs, and you have the
following:

myre = re.compile(r'http://[\w\.-/]+\.?(?![\w.-/])')

I understand \w stands for any word character, and \. means escaped
period, and ? means zero or one instances of a character or set.  I
did a myre.search('http://www.hotmail.com') which yielded a result, but
I am confused as to why

myre.search('http://www.sfgate.com/cgi-bin/article.cgi?f=/gate/archive/2003/06/29/gavin29.DTL')

would work, since there is a '=' and you don't provide for one in the
regular expression.  I guess I also am confused why you have a '(?!'
after you allow for zero or one period.