^(<[A-Za-z0-9]+>)*<H1>(<[A-Za-z0-9]+>)*([A-Za-z0-9]+)

Matches beggining, then '<', then the char class. Mabey you should change that to \w+ or [^<\/]+. Then the '>'. Now it matches that any amount of times, storing the opening tag right before '<H1>' in $1. If you don't use that tag, I would advise you take out the capturing parens and put in (?: ... ). Alright, let's move on ...

Next, it matches '<H1>' (and not '<h1>'). In the next set of parens, I think you need to take out the '<' and '>'. Also, you should match the '</h1>' tag as well. Then, it matches the next A-Za-z0-9 char. If you take out the '<' and '>' in that parens ($2 doesn't match unless you do) then there will be no A-Za-z0-9 chars left (the prev parens gobbled them up), so $3 would get the last char in between the header tag (due to backtracking).

You are checking $3 to see what's in between the header tags, and that confused me at first, but you aren't capturing anything in $2 because of those '<' and '>' chars.

Well, that was by no means a complete look at the regex, but it should have given you an idea about how errorprone parsing html is, I would look up on one of the modules like Parse::HTML to parse the html.

The 15 year old, freshman programmer,
Stephen Rawls


In reply to Re: (**corrected**) What Does This Line Do? by srawls
in thread (**corrected**) What Does This Line Do? by sfrattura

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.