As a meta-answer to you question, if you keep posting questions and don't get working answers, it's quite possible you are asking the wrong questions. A read through I know what I mean. Why don't you?, XY Problem and On Asking Questions of Bears might do you well. As well, if code provided doesn't work, make sure you are giving us good examples of input and output. It's also possible that regular expressions are not the right tool for the task you are trying to accomplish.

As well, as you've posted on this issue before, it's generally considered good form to keep it in a thread or at least cite your previous postings on the issue (I'm guessing Search for Second Occurence of Substing and get containing text and Searching string for paragraph..).

For your actual question, your specification leaves something to be desired. I will read it as "Extract all text following '===Comments===' until the next '=' or end of file and then extract all text following '=Aditional Notes=' until the next '=' or end of file". Note the misspelling of Aditional<sic>. The following will take your posted material and capture the strings in question into arrays. If this does not work for your actual text, post that case so we can have accurate input for test cases.

#!/usr/bin/perl use strict; use warnings; my $text = do { local $/; #slurp <DATA>; }; my @comments = $text =~ /(?<====Comments===).*?(?==|$)/gs; my @additional = $text =~ /(?<==Aditional Notes=).*?(?==|$)/gs; 1; __DATA__ ===Comments=== This webpage contains information bla bla bla =Section 2= Some more text here. ===Comments=== Some other comments here. =Another section= =Aditional Notes= More notes here.

In reply to Re: Extracting Text Using Regular Expressions Problem by kennethk
in thread Extracting Text Using Regular Expressions Problem by danj35

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.