$lines=~m/(<+)(\/?)(.+)(>+)/
This unfortuately is not the right approach. You regex will match quite a bit more than you expect.
You should look into a module like HTML::TokeParser.
Now getting back to why your regex wasn't helping:
m/(<+)(\/?)(.+)(>+)/
(<+) - capture one or more occurances of '<' so << or <<<<<<<<< will match and be captured to $1
(\/?) - capture zero or one '/' to $2. Not that this matters because if you use the uc function instead of your tr/// the '/' will be ignored
(.+) - capture 1 or more of anything but a line ending to $3. NOTE: this is greedy and will gobble everything in site unless it's required to finish the match
(>+) - capture one or more '>' (like >> or >>>>) to $4. NOTE: because the the '.+' is greedy you can have some very strange results with 2 '>' on a line whether or not it is in a tag.
imagine this line of HTML
look at this <<<----- <b>It is really neat</b> I swear >>
What will be captured to $3 is
----- <b>It is really neat</b> I swear
One tool to add to your regex arsenal is negated character classes like [^ ]. Rewriting your regex like /<([^>]+)>/ would get you closer, but still is not what you want. You can read more about negated character classes in perlre
Writing a HTML parser with a regex is a somewhat like hammering a nail with a flounder. You should really look for right tool in perl, in this case a true parser is going to help you out a lot.
grep
grep> cd /pub grep> more beer |
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.