正则表达式捕获功能

前端之家收集整理的这篇文章主要介绍了正则表达式捕获功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/env perl
print "\nReceived signal at ",scalar localtime,"\n";
sub test1
{
        $_ = 'http://www.perl.com/index.html';
        if (m#([^:]+)://(.*)#){
                print "\$1,\$2 = $1,$2 \n";
                if ($2 =~  m#([^/]+)/(.*)#){
                         print "\$1,$2 \n";
                         if ($2 =~ m#([^/]+)(.*)#){
                                 print "\$1,$2 \n";
                         }
                }
                 print "\$1,$2 \n";
        }
}
&test1;

[root@master ~/perl]# ./trap.pl

Received signal at Sun Dec 15 17:32:31 2013

$1,$2 = http,www.perl.com/index.html

$1,$2 = www.perl.com,index.html

$1,$2 = index.html,

$1,index.html #退出内层作用域后,又恢复了原来的值

原文链接:https://www.f2er.com/regex/362260.html

猜你在找的正则表达式相关文章