Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 多行正则表达式_Regex_Perl_Ultraedit - Fatal编程技术网

Regex 多行正则表达式

Regex 多行正则表达式,regex,perl,ultraedit,Regex,Perl,Ultraedit,我正在尝试匹配此文本: <a href="http://english317.ning.com/profiles/blogs/bad-business-writing-487">Continue</a> </div> <p class="small">

我正在尝试匹配此文本:

<a href="http://english317.ning.com/profiles/blogs/bad-business-writing-487">Continue</a>
                                      </div>
                <p class="small">

                                                    Added by <a href="/profile/KemberleyRamirez">Kemberley Ramirez</a> on September 2, 2010 at 11:38pm   

于2010年9月2日晚上11:38添加

我想在/blogs(例如“bad-business-writing-487”)之后获得文本,并在字符串(学生姓名和提交日期)之后添加文本(例如“Kemberley Ramirez于2010年9月2日晚上11:38”)


我将UltraEdit与Perl表达式一起使用。

s和/m修饰符控制如何处理多行。 看

您可能需要类似于带有/s修饰符的rrr reg.exps的内容,或者类似以下内容:(未测试)


$foo=~m| blogs/([^“]+).*由]+>([^添加的以下内容应适用于多行:

.*blogs\/(\S+)".*\(\n.*\)*<a.*>(.*)<\/a>(.*)
*博客\/(\S+)。*\(\n.*)*(.*)(.*)(.*)

我不知道您到底想匹配什么,但最好使用合适的HTML解析器:

#!/usr/bin/perl

use strict; use warnings;

use HTML::TokeParser::Simple;

my $parser = HTML::TokeParser::Simple->new(\*DATA);

my $blog_re = qr{^http://english317.ning.com/profiles/blogs/(.+)\z};
my $profile_re = qr{^/profile/(\w+)\z};

while ( my $tag = $parser->get_tag('a') ) {
    next unless my ($href) = $tag->get_attr('href');
    if ( $href =~ $blog_re or $href =~ $profile_re ) {
        print "[$1]\n";
    }
}

__DATA__
<a href="http://english317.ning.com/profiles/blogs/bad-business-writing-487">Continue</a>
                                      </div>
                <p class="small">

                                                    Added by <a href="/profile/KemberleyRamirez">Kemberley Ramirez</a> on September 2, 2010 at 11:38pm
!/usr/bin/perl
使用严格;使用警告;
使用HTML::TokeParser::Simple;
my$parser=HTML::TokeParser::Simple->new(\*数据);
我的$blog\u re=qr{^http://english317.ning.com/profiles/blogs/(.+)\z};
我的$profile_re=qr{^/profile/(\w+)\z};
while(my$tag=$parser->get_tag('a')){
下一步除非my($href)=$tag->get_attr('href');
如果($href=~$blog\u re或$href=~$profile\u re){
打印“[$1]\n”;
}
}
__资料__

于2010年9月2日晚上11:38添加

在“点匹配新行”模式下使用PowerGrep,我得出了以下结论:

(?>profiles/blogs/(.*?)").*?added by(.*?)</a>(.*?2010.*?\d{2}[ap]m)
(?>profiles/blogs/(.*)).*?由(.*)(.*2010.*d{2}[ap]m)添加
(然后是额外的处理搜索)

你可能会发现这个网站很有用:regexlib.com/I没有问我是否应该,我问了如何去做。在这种情况下,标签通常都在同一个地方用REGEX解析,这是完全可行的。
(?>profiles/blogs/(.*?)").*?added by(.*?)</a>(.*?2010.*?\d{2}[ap]m)