2009-09-29 3 views
0

이 정규식을 사용하여 POP3 유효한 전자 메일 콘텐츠를 추출하려고합니다.유효한 형식 문자열로 전자 메일 콘텐츠 (pop3)를 추출하는 방법

전체 내용을 <script> ... </script><style> ... </style>으로 제거했습니다.

모든 <br> 태그를 "\ n"로 변환했습니다.

나는 모든 HTML 태그를 제거하고 같은

regex = "<[^>]*>"; 

같은 정규 표현식을 사용하여 문자열로 모든 이메일의 내용을 (이 아닌 자신의 속성 값 &에만 태그를 제거합니다) 추출했다.

나는

이 PLZ 브라우저에서 페이지 소스보기 모드에서이 메시지를 읽을 여분의 공백을 작성 메일 & 줄 바꿈을 추가했습니다. 그래서 지금 내가 필요한 것을 이해할 수 있습니다.

메일 작성의 내용은 다음과 같습니다

Testing white space: 
hi   hello then   whats up man.,   is it cool 

The   policy set up by your  network administrator  requires that you authenticate yourself with this firewall before you can have access.        To authenticate yourself click on the following link and enter your user name   and  password to log in to the firewall. 

메일은 같은 POP3에서 검색 :

<html><body><span style="font-family:Verdana; color:#000000; font-size:10pt;"><div><span style="font-family: Verdana; color: rgb(0, 0, 0); font-size: 10pt;"><span style="font-family: Verdana; color: rgb(0, 0, 0); font-size: 10pt;"><font style="font-family: Verdana;" color="#000000" size="2" face="Verdana"><font style="font-family: Verdana;" color="#000000" size="2" face="Verdana"><font style="font-family: Verdana;" color="#000000" size="2" face="Verdana"><font style="font-family: Verdana;" color="#000000" size="2" face="Verdana">Testing white space:<br>hi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hello then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; whats up man.,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is it cool<br><br>The&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
policy set up by your &nbsp; &nbsp; &nbsp;&nbsp; network administrator&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; requires that 
you authenticate yourself with this firewall before you can have 
access.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To authenticate yourself click on 
the following link and enter your user name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and &nbsp; &nbsp; &nbsp;&nbsp; 
password to log in to the firewall. </font></font></font></font></span></span></div></span></body></html> 

HTML 코드 위에서 형식화 된 문자열 :

Testing white space: 
hi hello then whats up man., is it cool 

The 
policy set up by your network administrator requires that 
you authenticate yourself with this firewall before you can have 
access. To authenticate yourself click on 
the following link and enter your user name and 
password to log in to the firewall. 

여분의 공백을 하나의 공백으로 제거하고 두 개 이상의 연속 줄 바꿈이있는 경우 두 줄 바꿈으로 바꿉니다.

서식이 지정된 문자열에서 "The"와 "policy"사이에 원하지 않는 줄 바꿈이 있습니다. 나는 그것이 왜 일어날 지 예측할 수 없다. 나는 그것이 POP3에 의해 추측된다고 생각한다. 누구든지 정확하게 문자열의 서식을 지정할 수 있습니까? 미리 감사드립니다.

답변

0

HTML에서 줄 바꿈 문자는 공백으로 간주됩니다. 검색된 메일의 개행 문자를 단일 공백으로 바꾸면 <br>을 개행 문자로 변환하기 전에 예상 결과를 얻어야합니다.

관련 문제