<pre name="code" class="sql">* 表示0次或多次
[root@master ~]# cat 1.pl
$_="aabb";
if ( $_ =~ /aa\sbb/){print "1111111111\n"};
[root@master ~]# perl 1.pl
[root@master ~]#
[root@master ~]# cat 1.pl
$_="aa bb";
if ( $_ =~ /aa\sbb/){print "1111111111\n"};
[root@master ~]# perl 1.pl
1111111111
[root@master ~]# cat 1.pl
$_='#aTime';
if ($_ =~ /^#\s*Time/){print "11111111\n"};
[root@master ~]# perl 1.pl
---匹配0个空格
[root@master ~]# cat 1.pl
$_='#Time';
if ($_ =~ /^#\s*Time/){print "11111111\n"};
[root@master ~]# perl 1.pl
11111111
--匹配1个空格
[root@master ~]# cat 1.pl
$_='# Time';
if ($_ =~ /^#\s*Time/){print "11111111\n"};
[root@master ~]# perl 1.pl
11111111
--匹配多个空格
[root@master ~]# cat 1.pl
$_='# Time';
if ($_ =~ /^#\s*Time/){print "11111111\n"};
[root@master ~]# perl 1.pl
11111111
-------------------------------------------------
+ 是一个特殊字符,表示匹配"+前边内容一次或多次。
[root@master ~]# cat 1.pl
$_="aa bb";
if ( $_ =~ /aa\s+bb/){print "1111111111\n"};
[root@master ~]# perl 1.pl
1111111111
----------------------------------------------
? 表示零或一次
[root@master ~]# cat 1.pl
$_="aabb";
if ( $_ =~ /aa\s?bb/){print "1111111111\n"};
[root@master ~]# perl 1.pl
1111111111
[root@master ~]# cat 1.pl
$_="aa bb";
if ( $_ =~ /aa\s?bb/){print "1111111111\n"};
[root@master ~]# perl 1.pl
1111111111
[root@master ~]# cat 1.pl
$_="aa bb";
if ( $_ =~ /aa\s?bb/){print "1111111111\n"};
[root@master ~]# perl 1.pl
[root@master ~]#
perl ? * + 和空格结合
最新推荐文章于 2023-08-05 22:59:45 发布