Tim*_*Tim 18 regex unicode perl
哪些字符可以用作Perl正则表达式的分隔符?m/re/
,m(re)
并且måreå
似乎都工作,但我想知道所有的可能性.
当前词法分析器中存在一个错误,有时会阻止将 UTF-8 字符用作分隔符,即使您可以在不处于完整 Unicode 模式的情况下通过它偷偷使用 Latin1。
通常情况下,我想"我能写一个Perl程序来回答这个问题吗?".
这是尝试所有可打印ASCII字符的非常好的第一近似值:
#!/usr/bin/perl
use warnings;
use strict;
$_ = 'foo bar'; # something to match against
foreach my $ascii (32 .. 126) {
my $delim = chr $ascii;
next if $delim eq '?'; # avoid fatal error
foreach my $m ('m', 'm ') { # with and without space after "m"
my $code = $m . $delim . '(\w+)' . $delim . ';';
# print "$code\n";
my $match;
{
no warnings 'syntax';
($match) = eval $code;
}
print "[$delim] didn't compile with $m$delim$delim\n" if $@;
if (defined $match and $match ne 'foo') {
print "[$delim] didn't match correctly ($match)\n";
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10036 次 |
最近记录: |