单词边界:
匹配单词边界,就是位于单词(w)和非单词字符(W)之间的零宽度的地方。
就是单词前后必须跟非单词字符
[oracle@jhoa big]$ cat 11.pl
#$var = "The Great Fred";
$var = "Fred erick the Great";
if ($var =~/Fred/){print "$var
"};
[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 =~/Fred/){print "$var
"};
[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 =~/Fred/){print "$var
"};
[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 =~/Fred/){print "$var
"};
[oracle@jhoa big]$ perl 11.pl
!Fred erick the Great
[oracle@jhoa big]$
单词前面出现非单词字符,可以匹配
[oracle@jhoa big]$ cat 11.pl
#$var = "The Great Fred";
$var = "Fred! erick the Great";
if ($var =~/Fred/){print "$var
"};
[oracle@jhoa big]$ perl 11.pl
Fred! erick the Great
[oracle@jhoa big]$
单词后面出现非单词字符,可以匹配