In code in my Re^2: creating qr from existing regex reply to bart, there is the possibility of creating an empty  (?) embedded pattern-match modifier construct. However, all the docs I've seen specify:

"(?adlupimsx-imsx)"
"(?^alupimsx)"
        One or more embedded pattern-match modifiers ...
(emphasis added), not zero. Note, though, that (all) the docs go on to say:
This is particularly useful for dynamic patterns, such as those read in from a configuration file, taken from an argument, or specified in a table somewhere.
To me, dynamic generation implies the possibility of zero modifiers: one should seek to support the most general case.

The code here and below works with an empty  (?) construct for Perl standard releases 5.8 - 5.14, all I can test with ATM. (I haven't tested with other modifier groupings than i or not-i.)

c:\@Work\Perl\monks>perl -wMstrict -le "my $string = '/.*u\/ba$/'; ;; my $flag = qr{ [msix] }xms; ;; my $convertable = my ($pattern, $modifiers) = $string =~ m{ \A \s* / (.*?) / ($flag*) \z }xms; die qq{bad rx: '$string'} unless $convertable; ;; my $rx = qr{(?$modifiers)$pattern}; print $rx; print 'A: match' if 'u/ba' =~ $rx; ;; my $ry = qr{ \A foo $rx }xms; print $ry ;; print 'B: match' if 'foolubatu/ba' =~ $ry; print 'C: match' if 'Foolubatu/ba' =~ $ry; " (?-xism:(?).*u\/ba$) A: match (?msx-i: \A foo (?-xism:(?).*u\/ba$) ) B: match

My Questions:


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


In reply to Regex: Embedded pattern-match modifiers: Empty (?) modifier by AnomalousMonk

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.