Your regex does seem to do something for me... but what does your $text contain? If you're reading it from a file, are you reading the file line-by-line or are you slurping it all at once? There are several things I could point out about the regex, like how I'm not sure what (.{0,0})\K is supposed to be doing, or that the dots . will match anything, including newlines (because of /s) and dashes. But reviewing the regex doesn't make much sense without knowing what it's supposed to match against - please provide an SSCCE with several examples of what should match and what shouldn't!

use Data::Dump; dd "---\nFoo\n---\nBar\n" =~ /(.{0,0})\K(---\s*)(.{0,200})/gisx; __END__ ("", "---\n", "Foo\n---\nBar\n")

Also, note that you could set the input record separator $/ to something like "---\n" to read a file in chunks separated by that string.


In reply to Re: regex to match "---" followed by new line by haukex
in thread regex to match "---" followed by new line by Anonymous Monk

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.