Greedy operators, as explained by broquaint, gobble up as much of the input text as possible that still allows the regex to match. AIUI, if the match fails, perl's regular expression engine will force one character (unicode aside) from the text matched by the .* to be "given back", to see if the rest of the expression can match. (Caveat: I've realised I need to read O'Reilly's "Mastering Regular Expressions" again, so this might well be wrong.)

Looking at the regex you've created, I can't see any advantage to making the quantifiers non-greedy - they all need to match to the end of the line anyway.

If you're looking for a robust solution, then, as I mentioned in the CB, I'd recommend installing HPUX::Ioscan and using that, or at least looking at the code to see how it does it. (Hint: It does it by looping over each line)

Summary: I think your regex is fine (although you forgot the "Class\n======\n" header at the start of your example output, so the regex won't work), although I'd still advocate using the module

cheers
davis
Is this going out live?
No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist

In reply to Re: A query on greedy regexps by davis
in thread A query on greedy regexps by sch

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.