Regex 正则表达式从特定表达式捕获多行,直到Perl中的第一个空行

Regex 正则表达式从特定表达式捕获多行,直到Perl中的第一个空行,regex,perl,Regex,Perl,我有这个文件,我想匹配#sent_id=\d+和空行之间的所有内容。 这是我的档案: #新文档 #纽帕 #已发送\u id=1 #text=2019年,非技术专业人士的啤酒。 1 2019 NUM u5 nummod uuSPACEAFTER=否 2,点1点_ 3联合国数据确定=独立性|性别=Masc |数字=Sing | PronType=第5条数据_ 4 bon bon ADJ性别=Masc数字=Sing 5 amod_ 5 cru cru名词u性别=Masc |数字=Sing 0根u_ 6

我有这个文件,我想匹配#sent_id=\d+和空行之间的所有内容。 这是我的档案:

#新文档
#纽帕
#已发送\u id=1
#text=2019年,非技术专业人士的啤酒。
1 2019 NUM u5 nummod uuSPACEAFTER=否
2,点1点_
3联合国数据确定=独立性|性别=Masc |数字=Sing | PronType=第5条数据_
4 bon bon ADJ性别=Masc数字=Sing 5 amod_
5 cru cru名词u性别=Masc |数字=Sing 0根u_
6浇注ADP uu8箱u_
7 les le DET | DET | DET=Def | Gender=Masc | Number=Plur | PronType=第8条DET |_
8业余爱好者业余名词uu性别=Masc数量=Plur 5 nmod_
第9起ADP案件(10起案件)_
10技术名词uu性别=Fem |数字=Sing 8 nmod uu空格后=No
11  .   .   点u 5点u u空间安全设置=\n
#已发送\u id=2
#text=L'année aétégéné重用创新承诺。瞧,这六种护理方法都是技术性的。
1 L'L'PROPN u5 nsubj uuu SpaceAfter=否
2 année année名词u性别=Fem |数字=Sing 1 nmod_
3 a avoir AUX | Mood=Ind | Number=Sing | Person=3 | Tense=Pres | VerbForm=Fin 5 AUX:Tense |_
4ététre AUX|Gender=Masc|Number=Sing|Tense=pass|VerbForm=Part 5 cop|_
5 généreuse généreux ADJ uGender=Fem | Number=Sing 0 root_
6 en ADP案例7_
7创新名词uu性别=Fem |数字=Plur 5 obl u_
8个promettes prometter ADJ uu Gender=Fem | Number=Plur 7 amod uuu SpaceAfter=No
9   .   .   点10点_
10 Voici Voici动词意合_
11 les le DET | DET | DET=Def | Gender=Fem | Number=Plur | PronType=第13条DET |_
12六六个数字13个数字_
13趋势趋势名词uu性别=Fem |数字=Plur 10对象u_
14 qui qui PRON uu PronType=Rel 15 nsubj u_
15 pourreaient pouvoir动词| Mood=Cnd | Number=Plur | Person=3 | Tense=Pres | VerbForm=Fin 13 acl:relcl |_
16 bousculer-bousculer-VerbForm=Inf 15 xcomp_
17 notre son DET | Gender=Masc | Number=Sing | Poss=Yes | PronType=Prs 18 DET |_
18 paysage paysage名词uu性别=Masc |数字=Sing 16 obj u_
19 technologique technologique ADJ uu性别=Masc |数字=Sing 18 amod uuu SpaceAfter=No
20  .   .   点u 5点u u空间安全设置=\n
#已发送\u id=3
#text=香港,逮捕和侮辱,情况完全相同。
1 AáADP 2案例_
2 Hongkong Hongkong PROPN\u0 root\uspaceafter=否
3,点2点_
第4-5页_
ADP的4个案例(6个案例)_
5 les le DET | DET | DET=Def | Gender=Fem | Number=Plur | PronType=第6条DET |_
6个中心名词uu性别=Fem |数字=Plur 2 nmod u_
7 d'd'PROPN u6 appos uuu SpaceAfter=否
8逮捕逮捕名词u性别=Fem |数字=Plur 7单位:名称u_
九宗个案_
10 d'd'PROPN u6 nmod uu SpaceAfter=否
11冒犯冒犯名词u性别=Masc |数字=Plur 10单位:名称u空格后=No
12,点14点_
13联合国确定=独立|性别=有限元|数字=歌唱| PronType=第14条确定|_
14情境名词uu性别=Fem |数字=Sing 10 appos u_
15 qui qui PRON u PronType=Rel 16 nsubj_
16语义动词|语气=Ind |数字=Sing | Person=3 |时态=Pres | VerbForm=Fin 14 acl:relcl |_
17««点»18点»空间后=
18 désespérée désespéréADJ u2; Gender=Fem | Number=Sing 16 xcomp u2; SpacesAfter=
19»»点u18点uuu空间后=否
20  .   .   点u u10点u u空间安全设置=\n
#已发送\u id=4
#text=在米伽波尔工作的人员。“这是2019年《2020年报告》的三个版本,是一个组织机构的联盟。
第1-2页_
1个ADP案例(3个案例)_
2 les le DET | DET | DET=Def | Gender=Fem | Number=Plur | PronType=第3条DET |_
3 dizaines dizaine名词uu性别=有限元|数字=加9 nsubj u_
ADP的4个案例(5个案例)_
5毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫名词_
6德ADP案(7例)_
7个人名词uu性别=Fem |数字=Plur 5 nmod u_
8 ont avoir AUX | Mood=Ind | Number=Plur | Person=3 | Tense=Pres | VerbForm=Fin 9 AUX:Tense |_
9 défilédéfiler动词uu性别=Masc |数字=歌唱|时态=过去|动词形式=第31部分ccomp |_
10例dans dans ADP 12例_
11 la le DET | DET | dem=Def | Gender=Fem | Number=Sing | PronType=第12条DET |_
12 mégapole mégapole名词u性别=Fem |数字=Sing 9 obl:arg uspaceafter=No
13  .   .   点17点_
14««点»17点»空间后=
15 C'C'PROPN u17 nsubj uuu SpaceAfter=否
16表示情绪的词=Ind | Number=Sing | Person=3 | Tense=Pres | verform=Fin 17 cop |_
17三段三段调整uu性别=Masc |数字=Sing 9 xcomp u_
18你是谁?23马克_
19个son DET |性别=Fem |数字=Plur | Poss=Yes | PronType=Prs 20个DET |_
20展示展示名词u性别=Fem |数字=Plur 23 nsubj u_
21德ADP案件22_
22
sub extract_dependancies{

    open my $fh, "<:encoding(utf-8)", shift or die "$!\n";
    undef $/;
    my $file = <$fh>;
   # sent_id to blank line
    while($file =~ /^#\ssent.+\d+(.+)^$/msg){
        my $sentence = $1;
        #next if $sentence !~ /d+\tobj/;
    }
}
use warnings;
use strict;
use feature 'say';

die "Usage: $0 file\n" if not @ARGV;

my @sentences;

# First pass lines until the first  "# sent_id =..." (and that one)
while (<>) { last if /^\s*#\s*sent_id/ }

local $/ = "\n\n";  # read in blocks of up to an empty line

while (<>) {
    # Remove the leading line "# sent_id =...", return the rest
    push @sentences, s{ ^ \#\s* sent_id\s* = \s*[0-9]+ .*?\n }{}xr;
}

say for @sentences;
use warnings;
use strict; 
use feature 'say';

die "Usage: $0 file\n" if not @ARGV;

my $content = do { local $/; <> };

my @sentences;

while ( $content =~ / \#\s* sent_id \s*=\s* [0-9]+ .*? \n /gx ) {
    push @sentences, $content =~ /\G (.*?) (?:\n\n|$)/sx;
    #say "pos = ", pos $content;
}

say for @sentences;
use warnings;
use strict;
use feature 'say';

die "Usage: $0 file\n" if not @ARGV;

my $content = do { local $/; <> };

my @sentences = 
    $content =~ / \#\s*sent_id\s*=\s*[0-9]+ .*?\n (.+?) (?:\n\n|$) /gsx;

say for @sentences;
use strict;
use warnings;
use feature 'say';

my @blocks;

{
    local $/ = "\n\n";
    @blocks = map { /(# sent_id = .*)/s } <>;
}

say for @blocks;

perl -ne '$f=0 if /sent_id/; print "$_" if $f; $f=1 if /sent_id/' french.in > french.out
perl -MO=Deparse -ne '$f=0 if /sent_id/; print "$_" if $f; $f=1 if /sent_id/' french.in

LINE: while (defined($_ = readline ARGV)) {
    $f = 0 if /sent_id/;
    print "$_" if $f;
    $f = 1 if /sent_id/;
}