perl正则表达式元字符常量化
时间:2009-05-30 来源:aqcjsy1
perl正则表达式中,\Q用于是元字符常量化,例如
C:\Perl\bin>perl
$what = "[box]";
foreach (qw(in[box] out[box] white[sox])) {
if (/\Q$what\E/) {
print "$_ matched!\n";
}
}
^D
in[box] matched!
out[box] matched! C:\Perl\bin>perl
$what = "[box]";
foreach (qw(in[box] out[box] white[sox])) {
if (/$what\E/) {
print "$_ matched!\n";
}
}
^D
in[box] matched!
out[box] matched!
white[sox] matched!
$what = "[box]";
foreach (qw(in[box] out[box] white[sox])) {
if (/\Q$what\E/) {
print "$_ matched!\n";
}
}
^D
in[box] matched!
out[box] matched! C:\Perl\bin>perl
$what = "[box]";
foreach (qw(in[box] out[box] white[sox])) {
if (/$what\E/) {
print "$_ matched!\n";
}
}
^D
in[box] matched!
out[box] matched!
white[sox] matched!
相关阅读 更多 +
排行榜 更多 +