2012-04-09 2 views
0

나는 이메일 세트를 텍스트 파일에 가지고있다. 나는 그것에서 몸을 추출하고 싶다. 샘플 문서는 다음과 같습니다.이메일의 텍스트 마이닝

Email: 1 
=============== 


    MIME-Version: 1.0 
    Received: by 10.68.8.6 with HTTP; Sat, 7 Apr 2012 01:04:45 -0700 (PDT) 
    Date: Sat, 7 Apr 2012 13:34:45 +0530 
    Delivered-To: [email protected] 
    Message-ID: <[email protected]om> 
    Subject: hello 
    From: twisty princess <[email protected]> 
    To: twisty princess <[email protected]> 
    Content-Type: multipart/alternative; boundary=047d7b33d826e6762004bd1239b5 
    --047d7b33d826e6762004bd1239b5    
    Content-Type: text/plain; charset=ISO-8859-1 

    hey How are you doing? 

    --047d7b33d826e6762004bd1239b5  
    Content-Type: text/html; charset=ISO-8859-1 

    <br><br>hey How are you doing?<br> 

    --047d7b33d826e6762004bd1239b5-- 

그래서이 텍스트에서 "어떻게 지내세요?"라고 말하면됩니다. 정규식과 C#을 사용하여이 작업을 수행하고 싶습니다. 감사합니다

+0

하나의 텍스트 파일과 이러한 섹션이 여러 개 있습니까? 모든 전자 메일이 대칭/동일한 형식을 따르고 있습니까? Email : 1 및 텍스트 파일의 이중선 구분 기호 또는 SO에 삽입 했습니까? –

+0

예 모든 전자 메일의 형식이 동일합니다. – Cyang

답변

1

사용 정규식 boundary=([^\s]+) 찾을 경계 이름

var bname = _boundaryRegex.Match(text).Groups[1].Value; 

그런 다음 사용하여 텍스트 서식을 캡처 정규식 bname 그것은 값 boundary 매개 변수의를 발견하고 --BOUNDARY 라인 beetween 텍스트를 일치 시키려고

var textCapturer = new Regex(string.Format("--{0}(?<text>.*?)(?=--)",bname); 
foreach(var match in textCapturer.Matches(text)) 
{ 
    Console.WriteLine(match.Groups["text"]); 
} 

.

비록 정규식을 사용하여 이런 종류의 구문 분석을 수행하지 않겠지 만.

+0

사용 방법을 보여 줄 수 있습니까? – Cyang

+0

수정 사항을 확인하십시오. –

관련 문제