http://qs321.pair.com?node_id=78769

deryni has asked for the wisdom of the Perl Monks concerning the following question:

I ask for any and all monks whose knowledge of regular expressions exceeds my own to help me optimize this regex.
Optimize for speed or readability the choice is yours. I am parsing computer generated, badly formatted, HTML which has a number of lines that look like this
<tr> <td width="0" align="center"><font face="Arial" size="2">29022</font> </td><td width="0" align="center"><font face="Arial" size="2">01</font +> </td><td width="0" align="center"><font face="Arial" size="2">354</fon +t> </td><td width="0" align="center"><font face="Arial" size="2">201</fon +t> </td><td width="0" align="center"><font face="Arial" size="2">01</font +> </td><td width="0" align="center"><font face="Arial" size="2">&nbsp;</ +font> </td><td align="center"><font face="Arial" size="2">INTRODUCTION TO FI +LM</font> </td><td align="center"><font face="Arial" size="2"> 3</font> </td><td align="center"><font face="Arial" size="2">MW5M7,8</font> </td><td align="center"><font face="Arial" size="2">MI-100</font> </td><td align="center"><font face="Arial" size="2">&nbsp;</font> </td></tr>
The first piece of data is always 5 digits, the second 2, the third 3, the fourth 3, the fifth 2, the sixth a $nbsp or a single letter, the seventh an unspecified number of words, the eigth a single space followed by a digit, the ninth will always have 1 letter and then will either be another letter followed by a number or two numbers (that will possibly be followed by another similar set, as shown above), the tenth will always be letters followed by a dash and then some numbers or letters, and finally the eleventh can be ignored.

I am currently using /^<tr.*?(\d\d\d\d\d).*?<td.*?>(\d\d).*?<td.*?>(\d\d\d).*?<td.*?>(\d\d\d).*?<td.*?>(\d\d).*?<td\.*?>(?:&).*?<td.*?>(\w+(?:(?:\s\w+)?)*).*?<td.*?>(\s\d).*?<td.*?>(\w(?:(?:[\w\d,])?)*).*?<td.*?>(\w(?:\(?:[\w\d-])?)*)/ to pull out the relevant pieces of information. Any advice would be appreciated.

-Etan

P.S. Oh and if possible some slight explanation would be useful. I understand the basics of regex but flags and oddities still escape me. Thanks in advance.

P.P.S I had been checking for both the <td> and <font> tags but then read this node and realized that I was asking for too much. So I stopped asking for the font tags. Just thought I'd throw that in to put my thought processes up for inspection.