Can someone translate the following into a single line?
It's from the sgml library and is supposed to allow me to find the
attributes within a tag. I have a version of the pcre, but I don't know
what the second and third lines are supposed to do.
attrfind = re.compile(
'[%s]*([a-zA-Z_][-.a-zA-Z_0-9]*)' % string.whitespace
+ ('([%s]*=[%s]*' % (string.whitespace, string.whitespace))
+ r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./:+*%?!\(\)_#=~]*))?')
I thought it was
'[ ]*([a-zA-Z_][-.a-zA-Z_0-9]*)([ ]*=[ ]*('[^']*'|\"[^\"]*\"|[-a-zA-Z0-9./:
+*%?!\\_#=~]*))?'
but that doesn't seem to work quite right. I guess I don't know what the r
does in the third line.
I am assuming that for the tag
<a href="http://someurl/page.html">
I would get href, and http://someurl/page.html for the attributes from the
re.match command.
Any help would be appreciated.
Bill