单词边界:
\b匹配单词边界,就是位于单词(\w)和非单词字符(\W)之间的零宽度的地方。
就是单词前后必须跟非单词字符
[oracle@jhoa big]$ cat 11.pl
#$var = "The Great Fred";
$var = "Fred erick the Great";
if ($var =~/\bFred\b/){print "$var\n"};
[oracle@jhoa big]$ perl 11.pl
Fred erick the Great
[oracle@jhoa big]$ cat 11.pl
#$var = "The Great Fred";
$var = "aFred erick the Great";
if ($var =~/\bFred\b/){print "$var\n"};
[oracle@jhoa big]$ perl 11.pl
[oracle@jhoa big]$
Fred前面出现单词字符 ,匹配不上
[oracle@jhoa big]$ cat 11.pl
#$var = "The Great Fred";
$var = "Freda erick the Great";
if ($var =~/\bFred\b/){print "$var\n"};
[oracle@jhoa big]$ perl 11.pl
[oracle@jhoa big]$
Fred后面出现单词字符匹配不上
[oracle@jhoa big]$ cat 11.pl
#$var = "The Great Fred";
$var = "!Fred erick the Great";
if ($var =~/\bFred\b/){print "$var\n"};
[oracle@jhoa
Perl 单词边界
最新推荐文章于 2022-07-22 20:27:07 发布