"단락의 일반 레이아웃"에는 더 나은 정의가 필요합니다. 입력과 예상 출력의 부족을 감안할 때 여기서 원하는 것을 맞춰야합니다. 나는 또한 당신이 어떤 언어라도 받아 들일 것으로 추측하고 있습니다. 여기에 perl
이 있습니다. 거의 익숙한 언어가 아닙니다.
가정되는 입력 :
do not match this line
[image.gif]
some words, usually a few lines
Bobert McBobson
emailaddress<mailto:[email protected]>
don't match this line either
[image.gif]
another few words
on another few lines
Bobina Robertsdaughter
emailaddress<mailto:[email protected]>
this line is also not for matching
예상 출력 :
[image.gif]
some words, usually a few lines
Bobert McBobson
emailaddress<mailto:[email protected]>
---
[image.gif]
another few words
on another few lines
Bobina Robertsdaughter
emailaddress<mailto:[email protected]>
perl
사용 해결책 :
#!/usr/bin/perl -n007
my $sep = "";
while (/(\[image\.gif\].*?<mailto:[^>]*>(\r)?\n)/gms) {
print $sep . $1;
$sep = "---$2\n";
}
perl
정규식 언어 왕; 많은 사람들이 그게 다 좋은 것이라고 말합니다. 여기서는 -n007
옵션을 사용하여 각 파일의 전체 내용을 읽고 기본 변수로 코드를 실행하도록 지정합니다.
$sep
은 두 번째 경기까지 분리 할 것이 없으므로 공백으로 시작합니다.
그런 다음 정규식과 일치하는 텍스트의 각 블록을 통해 루프 :
그런 다음 일치 항목을 인쇄하고 마침내 구분 기호를 세 개의 대시 및 줄 바꿈 (필요할 경우 DOS 줄 끝이 추가됨)으로 설정합니다.
이제 당신은 그것을 실행할 수 있습니다 :하여 Image.gif \]`하는 샘플 입력 발생하지 않습니다`에 대한
$ perl answer.pl input.txt
[image.gif]
some words, usually a few lines
Bobert McBobson
emailaddress<mailto:[email protected]>
---
[image.gif]
another few words
on another few lines
Bobina Robertsdaughter
emailaddress<mailto:[email protected]>
당신 테스트를. 질문을 수정할 수 있습니까? – trincot
느린'(? s) (? <= \ [image \ .gif \]). *? (? =
sln