Assuming you never have an empty <span></span> set, I believe the following should work, should it not?
s{((?:(?:<span>)?.(?:</span>)?){80})}{$1\n}g

No.

For illustrative purposes, assume that you want to match 10 characters rather than 80. That won't change the behavior. Let's try it on something simple like "<span>1</span>":

#!perl $_ = "<span>1</span>"; s{((?:(?:<span>)?.(?:</span>)?){10})}{$1\n}g; print "$_\n"; __END__ <span>1</s pan>
What happened? Well, perl tries hard to make the expression match. When it doesn't succeed at first by matching the initial span tag with the first optional group, it backtracks and matches that first "<" with the dot. This isn't restricted to one or two edge cases either. It may work for "<span>foo</span>" but only because "foo</span>" is exactly 10 characters. It won't work for "<span>fo</span>" or "<span>foob</span>". Of course, the examples would be different if you are trying to count 80 characters but the bug is the same.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: (counting chars but ignoring SPANs) Re4: highlight and line breaks by sauoq
in thread highlight and line breaks by glwtta

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.