Well, if you add /s to what you have, everything between and including $first and $last will be replaced. You say this didn't work for you?

Here's a useful mnemonic to remember the difference between /s and /m:

/s affects the meaning of a single regexp character (namely "."), while /m affects the meaning of multiple regexp characters (actually, just two: "^" and "$").
It's just a mnemonic, not the full story, but it comes in handy. With /m in effect, "^" matches not only the beginning of the string, but also the beginning of any line of text contained in the string (i.e. right after any embedded newlines). Likewise, with /m, $ will match the end of every line contained in the string, i.e. just before every newline contained in the string (though if the last character of the string is not a newline, then "$" matches the very end of the string). On the other hand, /s only makes "." match newlines too.

BTW, the parentheses in your regexp are superfluous, since you are not doing anything with the captured string, and in this case they are not needed for grouping either.

But despite my giving you these pointers on your regexp, I agree with merlyn that regexps are not the tool for this kind of problem.

the lowliest monk


In reply to Re: Replacing everything in between using s///; by tlm
in thread Replacing everything in between using s///; by JayBee

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.