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)"(emphasis added), not zero. Note, though, that (all) the docs go on to say:
"(?^alupimsx)"
One or more embedded pattern-match modifiers ...
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: <%-{-{-{-<
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |