2012-10-10 2 views
0

나는 "/index.html"("<"태그 (두 줄 전에)로 시작하는 줄)을 삭제하고이 줄을 지울 필요가있는이 줄이 있습니다. 같은 다른 모든 라인은검색어와 일치하는 여러 줄을 삭제하는 정규 표현식

예 :.

<a href="http://site.com/dir/file.html"> 
/dir/file.html</a>: 
../../../index.html<br> 
<a href="http://site.com/dir/file2.html"> 
/dir/file2.html</a>: 
../../../page.html<br> 
<a href="http://site.com/dir/name.html"> 
/dir/name.html</a>: 
../../../index.html<br> 
<a href="http://site.com/dir/any-link_.html"> 
/dir/any-link_.html</a>: 
../../../file-name.html<br> 

출력 :

<a href="http://site.com/dir/file2.html"> 
/dir/file2.html</a>: 
../../../page.html<br> 
<a href="http://site.com/dir/any-link_.html"> 
/dir/any-link_.html</a>: 
../../../file-name.html<br> 

그래서 정규 표현식은 삭제해야합니다 U가 "/index.html"이 앞에 오는 어떤 < (그 앞에 두 줄)을 붙이지 말고 다른 줄을 뒤에 둡니다.

나는 메모장 ++에서 ^./index.html과 같은 것을 시도했지만, "/index.html"이있는 행만 삭제하고, 전에는 <에서 시작하여 제거하는 방법을 모른다. 그것 2 라인.

+0

이것은 실제로 프로그래밍 질문이 아닙니다. [** superuser.com **] (http://superuser.com/)에 대해 묻는 것은 어떻습니까? – ghoti

답변

1
<a href="http://site\.com([^"]*\.html)">\s*\1</a>:\s*.*index.html<br>\s* 

경로 이름 뒤에 그대로 <a href="http:site.com, 일치, 다음 닫기 태그 다음에 파일 이름 (\1)의 repition 때까지 태그 (새 라인 포함)의 공백, 말, 콜론, 더 많은 공백 (개행을 포함하여), 그 다음 임의의 수의 문자 (줄 바꿈 제외) index.html<br> 다음 줄 (공백, 새 줄 바꿈 포함)

아마도 줄여서

.*\n.*\n.*index.html<br>\n 

. *을주의하고 의도하지 않은 부작용이 있습니다. 정규식은 가능한 한 구체적이어야하며 특히 삭제할 때 사용하십시오.

관련 문제