$constraint =~ m@ ^\s* # skip all whitespace at beginning ( /.+/ # capture the custom regex |m(.).+\2 # does this capture the ops? What does the |m do? +why is the (.) and \2 in there? ) [cgimosx]* # ?? don't understand what this is for. what are we t +rying to match? I thought the ops were matched above \s*$ # skip all whitespace at end @x
regexes can be in a number of ways. one, is the familiar /regex/flags. Another, is with the m// operator, which can have any thing instead of the "/". I think there are some other ways as well, but those are not matched by this regex.

the m(.).+\2 part of the regex is for matching m// type regexes. it says "Match an 'm', followed by any character (the delimiter), followed by at least one character (the regex itself), until you reach the delimiter again". a "\2" is a of using backreferences in regexes. It matches "whatever was in the 2nd set of ()s".

See man perlop for more details.

-- Dan


In reply to Re: A Regex to identify Regex's / Compiling a regex by zigdon
in thread A Regex to identify Regex's / Compiling a regex by knowmad

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.