Several issues here: First, you need a non-greedy quantifier. And while we're at it, I'm sure you want something captured, so lets use the + quantifier instead of * (which permits nothing).

Next, you must also realize that your text has "newline" characters embedded within it. The . (dot) metacharacter excludes newlines by default, unless you use the /s modifier on your regexp. Here's a "repaired" version:

my $source = << 'END'; adf <!-- InstanceBeginEditable name="guts" --> this is the part we want <!-- InstanceEndEditable --> adf <!-- InstanceBeginEditable name="crap" --> adf <!-- InstanceEndEditable --> adf END # Pull out just what we need my ($new_source) = $source =~ /<!-- InstanceBeginEditable name="guts" +-->(.?)<!-- InstanceEndEditable -->/s;

You're also not checking whether your regexp successfully matched or not, so when it silently fails, you simply get no text captured (in this example). You really ought to test whether a match took place or not.

One other word of warning: parsing HTML with a regular expression is fragile. You know, it's possible that a newline gets embedded in one of your HTML comments too, and that would break the regexp test. It's always advisable to use a HTML parser rather than rolling your own regexp approach.


Dave


In reply to Re: Help with Regex by davido
in thread Help with Regex by rsiedl

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.