일부 텍스트의 "사이"를 잡는 코드가 있습니다. , 구체적으로는 foo $someword
과 그 다음은 foo $someword
입니다.Perl 정규 표현식이 무한 루프를 일으키는 이유는 무엇입니까?
그러나 처음에는 "사이"에 갇혀서 어떻게 든 내부 문자열 위치가 증가하지 않습니다.
입력 데이터는 여기 저기에 개행 문자가있는 텍스트 파일로, 관련성이 적지 만 인쇄가 쉬워집니다.
my $component = qr'foo (\w+?)\s*?{';
while($text =~ /$component/sg)
{
push @baz, $1; #grab the $someword
}
my $list = join("|", @baz);
my $re = qr/$list/; #create a list of $somewords
#Try to grab everything between the foo $somewords;
# or if there's no $foo someword, grab what's left.
while($text=~/($re)(.+?)foo ($re|\z|\Z)/ms)
#if I take out s, it doesn't repeat, but nothing gets grabbed.
{
# print pos($text), "\n"; #this is undef...that's a clue I'm certain.
print $1, ":", $2; #prints the someword and what was grabbed.
print "\n", '-' x 20, "\n";
}
는하지 마십시오 당신이 원하는 "/ g "수정 자도 두 번째 루프에서? – jrockway
\ z와 \ Z는 필요하지 않습니다. \ Z는 \ z를 포함합니다. \ z –
배열을 잡는 것이 아니라 (그/g가 반환 할 것입니다) 텍스트를 걷고 있습니다. 그러나/g는 최종 출력 문제에 영향을주지 않습니다. 난 노력 했어. :-) –