6 Mar
2002
6 Mar
'02
8:16 p.m.
[Ed Colmar]
I'm working up a quick re to give me the folder above a webpage... For instance:
### I want: http://www.the.net/bigfolder/ ### import re url = "http://www.the.net/bigfolder/somepage.html" htmlfile = re.compile("/\w*\.html") htmlfile.match(href_url) if htmlfile: folder_url = htmlfile.sub(href_url, "/")
For some reason I cannot get my re to do this right...
Double each backslash, otherwise Python interprets them and removes them. This isn't new behavior, though, been around for years. Also, htmllfile.match should return a match object, so you really want something like: m=htmlfile.match(href_url) if m: ..... Cheers, Tom P