如何像使用 Perl 的quotemeta 函数( \Q..\E) 那样转义 Raku 正则表达式中的元字符?
也就是 Perl 代码
my $sentence = 'The quick brown fox jumped over the lazy dog';
my $substring = 'quick.*?fox';
$sentence =~ s{$substring}{big bad wolf};
print $sentence
Run Code Online (Sandbox Code Playgroud)
将每个.、*、 和?视为元字符,从而打印The big bad wolf jumped over the lazy dog。但是如果我将倒数第二行更改为$sentence =~ s{\Q$substring\E}{big bad wolf};,那么 Perl 会将其.*?视为文字字符,从而打印The quick brown fox jumped over the lazy dog。
如何按字面意思处理 Raku 正则表达式中的字符?
如何在 Raku 正则表达式中插入条件代码
正则表达式 与 Perl 正则表达式类似
my $F = 1;
'foobarbar' =~ / (?(?{ $F }) foo | bar ) bar /x ;
Run Code Online (Sandbox Code Playgroud)
辛苦了一天了,没有结果,请大家帮忙,谢谢。