... enclosing a regex in 'm()' ...

The
   m open-delimiter pattern close-delimiter
form is what I think of as the "canonical" form of the m// operator, where the delimiters can be a wide variety of characters including {} () <> [] matching braces. The // match form is a special case. Likewise the qr// s/// operators. This alleviates a lot of escape-ology connected with the / character in regexes. See perlop. (Note that q// qq// qx// qw// tr/// y/// and maybe some others also use this delimiter convention.)

What is the trailing xms doing?

I use the /ms modifiers as part of a standard "tail" on all my qr// m// s/// expressions to give the . ^ $ operators a standard | fixed behavior. This eliminates some degrees of freedom in regex behavior and makes them slightly easier to understand. The /x modifier in the standard tail enables the use of whitespace to help clarify a regex. See Modifiers in perlre.

(?: (?! </div) .)+

This has already been covered by GrandFather here. This expression just steps forward grabbing one character after another as long as that character is not a part of whatever matches the (?!...) negative lookahead expression, a closing div tag fragment in this case. A bit slow perhaps, but effective and flexible (update: flexible in that the lookahead expression can be of any complexity). See Lookaround Assertions in perlre; see also perlretut, perlreref and perlrequick.

(</div)?

Optionally capture a literal character sequence if it is present. The capture variable $1 (in this case) will hold the captured sequence if it was present, otherwise $1 will be undefined. See perlre, etc., as above.


Give a man a fish:  <%-{-{-{-<


In reply to Re^5: problem with optional capture group by AnomalousMonk
in thread problem with optional capture group by Special_K

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.