Thanks for the comments;
  Snax - you're right, I was using the opposite switch to the one I meant, but I still have the same greed problems.
  Japhy - This is new to me and it looks like the kind of solution I was after. However ?= matches nothing as (?=^ {3}\w), and I can't use \n, since then I skip my first record.

Any more ideas?
BTW: the 'record1' string is actually the first field of the record; it could be anything beginning with a \w

oh yeah, here's my test source:
#!/usr/bin/perl -w use strict; my($infile,@records); while(<DATA>) {$infile.=$;} @records = (split(/(?=^ {3}\w)/,$infile); #returns whole list #@records = ($infile =~ m/(^ {3}\w.*?)/sg); #returns only up to \w print join("\n========\n",@records); __DATA__ record1 field2 2345 record2 record3 field1 GAGGA field2 7848 field2a 5m

In reply to Re: Regex not greedy enough by Boldra
in thread Regex not greedy enough by Boldra

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.