You could always use a parser:

$grammar = <<'__END_OF_GRAMMAR__'; { use strict; use warnings; $skip = qr/[ \t]*/; } # Returns a ref to an array of lines. parse : line(s?) /$/ { $item[1] } # Returns a ref to an array of atoms and lists. line : term(s?) /\n/ { $item[1] } # Returns an atom or a list. # An atom looks like: [ atom => "text" ] # A list is a ref to an array of atoms and/or lists. term : '{' term(s?) '}' { [ list => $item[2] ] } | /[^{} \t\n]+/ { [ atom => $item[1] ] } __END_OF_GRAMMAR__

Update: Added missing closing square brackets.

Update: Tested:

use strict; use warnings; use Data::Dumper (); use Parse::RecDescent (); $::RD_HINT = 1; #$::RD_TRACE = 1; my $grammar = <<'__END_OF_GRAMMAR__'; { use strict; use warnings; $skip = qr/[ \t]*/; } # Returns a ref to an array of lines. parse : line(s?) /$/ { $item[1] } # Returns a ref to an array of atoms and lists. line : term(s?) /\n/ { $item[1] } # Returns an atom or a list. # An atom looks like: [ atom => "text" ] # A list is a ref to an array of atoms and/or lists. term : '{' term(s?) '}' { [ list => $item[2] ] } | /[^{} \t\n]+/ { [ atom => $item[1] ] } __END_OF_GRAMMAR__ my $p = Parse::RecDescent->new($grammar) or die("Bad grammar\n"); my $text = <<'__END_OF_TEXT__'; DataLine1 {error 1 1 {^E 0-20-9:0-50-9:0-50-9.*$} {^E 0-20-9:0-50-9:0- +50-9.*$}} {three 1 1 {^.*35=A.*$|^.*35=5.*$} {^.*35=A.*$|^.*35=5.*$}} + {fixv 1 1 ^.*VFIXFxProxy.*Disconnected ^.*VFIXFxProxy.*Disconnected} DataLine2 error 1 1 {^E 0-20-9:0-50-9:0-50-9.*$} {^E 0-20-9:0-50-9:0-5 +0-9.*$} {three 1 1 {^.*35=A.*$|^.*35=5.*$} {^.*35=A.*$|^.*35=5.*$}} { +fixv 1 1 ^.*VFIXFxProxy.*Disconnected ^.*VFIXFxProxy.*Disconnected} __END_OF_TEXT__ my $t = $p->parse($text) or die("Bad text\n"); print(Data::Dumper::Dumper($t)); __END__ output (reformatted for readability) ====== [ # Array of lines. [ # First line. [ atom => 'DataLine1' + ], [ list => [ [ atom => 'error' + ] , [ atom => 1 + ] , [ atom => 1 + ] , [ list => [ [ atom => '^E' + ] , [ atom => '0-20-9:0-50-9 +:0-50-9.*$' ] ] ] , [ list => [ [ atom => '^E' + ] , [ atom => '0-20-9:0-50-9 +:0-50-9.*$' ] ] ] ], [ list => [ [ atom => 'three' + ] , [ atom => 1 + ] , [ atom => 1 + ] , [ list => [ [ atom => '^.*35=A.*$|^. +*35=5.*$' ] ] ] , [ list => [ [ atom => '^.*35=A.*$|^. +*35=5.*$' ] ] ] ], ... ], [ # Second line. ... ], ]

Note: It's quite easy to modify the grammar to generate data in a different format. Let me know if you need help to do so.


In reply to Re: multiple matches in regex by ikegami
in thread multiple matches in regex by ww

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.