To start: I have a file that looks a bit like what's below, format-wise:
/* SOME COMMENT HERE */ /* MORE COMMENT */ /* Description - information */ options { option1 value; option2 value; option3 "value"; option4 { value1; value2; }; }; /* identifier1 ID 123456 */ object "identifier1" in { option1 value; option2 "value"; option3 { value1; value2; }; option4 { value; }; }; /* identifier2 ID 234561 */ object "identifier2" in { option1 value; option2 "value"; option3 { value1; value2; }; option4 { value; }; }; /* identifier3 ID 345612 */ object "identifier3" in { option1 value; option2 "value"; option3 { value1; value2; }; option4 { value; }; }; /* EOF */

I hope the anonymzing isn't too problematic.

At any rate, I need to pull data out of this file, and I can't guarantee the availability of any non-core modules on whatever system this ends up running on.

So, step 1 for me, is to get all the bits starting with object ... { and going until the next }; pulled out so I can deal with them from there. I'm thinking a regex that will grab each instance as a single multi-line string, and shoving them all into an array, but I'm open to suggestions. Each file may have rather a lot of these objects, but unfortunately I have no way of determining how many in advance.

What I've tried: I've been playing on Regex101 to test some various ideas and try to tweak a possible regex match. They don't have anything Perl-specific, but I've found it handy in the past for testing and tweaking. Alas, I keep ending up with everything or nothing. Getting the opening line or the closing line for each object is easy enough, but grabbing both and whever happens to be in between them is proving more problematic, and I end up with the everything-or-nothing problem.

Help, monks? Am I missing some blatently obvious solution?


What part of v_e = sqrt(2GM/r) don't you understand? It's only rocket science!

In reply to Regex Question by jedikaiti

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.