[PerlChina] regex问题:如何取得匹配的多行内容

chen ken tinyu0 at gmail.com
Wed Jun 14 23:40:09 PDT 2006


最近在学习正则表达式,碰到匹配多行文本的问题,怎么也弄不明白了 - -!
问题如下:

我把正则表达式在http://regexlib.com/RETester.aspx中测试,能匹配多行内容
我也在RegexBuddy中测试过,也能匹配多行
正则表达式:(Customer Address[\s][\.]*(?:[\s].*\n)*)
文本内容:

Customer Address .............. New Orchard Road
                                Armonk, NY 10504
                                US
Customer1 Address .............. New Orchard Road
                                 Armonk, NY 10504
                                 US

测试匹配结果
Customer Address .............. New Orchard Road
                                Armonk, NY 10504
                                US
$1=
Customer Address .............. New Orchard Road
                                Armonk, NY 10504
                                US


但是,我在perl中

my $regex = '(Customer Address[\s][\.]*(?:[\s].*\n)*)' ;
if($content =~ m/$regex/i){
    print $1, "\n";
}

只能打印出

Customer Address .............. New Orchard Road


这是怎么回事啊?我google上看了看,没有找到原因。
谁能给我解释一下么,谢谢。
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20060615/16f678c9/attachment.html 


More information about the China-pm mailing list