I hope this question is not a RTFM one.
I am trying to write a Python script that extracts links from a standard HTML webpage (the tags).
I hav
In response to question #2 (shouldn't a link be a well defined regular expression) the answer is ... no.
An HTML link structure is a recursive much like parens and braces in programming languages. There must be an equal number of start and end constructs and the "link" expression can be nested within itself.
To properly match a "link" expression a regex would be required to count the start and end tags. Regular expressions are a class of Finite Automata. By definition a Finite Automata cannot "count" constructs within a pattern. A grammar is required to describe a recursive data structure such as this. The inability for a regex to "count" is why you see programming languages described with Grammars as opposed to regular expressions.
So it is not possible to create a regex that will positively match 100% of all "link" expressions. There are certainly regex's that will match a good deal of "link"'s with a high degree of accuracy but they won't ever be perfect.
I wrote a blog article about this problem recently. Regular Expression Limitations