note
AnomalousMonk
<blockquote><i>
<c>$re = "(?:$flags:$core)";</c>
</I></BLOCKQUOTE>
<p>
That doesn't work: too many <c> ':' </C> (colons):
<c>
c:\@Work\Perl\monks>perl -wMstrict -le
"my $string = '/.*uba$/i';
;;
my $flag = qr{ [msixpodual] }xms;
;;
my $convertable =
my ($core, $flags) = $string =~ m{
\A \s* / (.*?) / ($flag*) \z
}xms;
die qq{bad rx: '$string'} unless $convertable;
;;
my $re = qq{(?:$flags:$core)};
print $re;
print 'A: match' if 'uba' =~ $re;
"
(?:i:.*uba$)
</C>
Something like this works:
<c>
c:\@Work\Perl\monks>perl -wMstrict -le
"my $string = '/.*u\/ba$/i';
;;
my $flag = qr{ [msixpodual] }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;
"
(?^:(?i).*u\/ba$)
A: match
(?^msx: \A foo (?^:(?i).*u\/ba$) )
B: match
</C>
Note that:
<ul>
<li>
I go directly to <c> qr// </C> form.
</LI>
<li>
The modifiers (<c>$flag</C> pattern) implemented vary by Perl version; see [doc://perlop].
</LI>
</UL>
</P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-634253">
<hr><p>Give a man a fish<b>:</B> <c> <%-{-{-{-<</C></P>
</div></div>
1208734
1208848