Sorry to re-submit this question again! Thank you for responding, nevertheless most of you may have assumed that each line is exactly 40 characters. That is not the case. I want to match lines in a block of text that
  1. Have 0-40 characters
  2. There can be from 0 - 4 lines in the block, but no more.

I need some help constructing a regular expression that can accomplish this. I have tried these 2 examples, but they dont work for me:

/(.{0,40}\n){0,4}/ /(?:.{0,40}\n){0,4}/m
The text is contained in a string, for example I would like to do this:

$foo = "1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890"; if ($foo =~ m/4 lines of 0 to 40 chars in length/) { do something }
Thanks again! Also, please no loops, the goal is to accomplish this with a single regex. If it is not possible, tell me. Cheers!

Robert


In reply to How do I match lines of UP TO 40 chars BUT NO MORE in a block of text? by kleinbiker7

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.