2016-08-09 5 views
0

전자 메일을 통해 회신하는 사용자가 있으며 테이블에 언급 된 날짜를 검색해야합니다. 당신이 볼 수 있듯이테이블에서 값을 검색하는 정규식

$temp = ($Mail.Body.Text -creplace '(?m)^\s*\r?\n' -split "User name`r`n`tLogon name`r`n`tEnd date`r`n`tNew end date")[1] 
(($temp -split "`r`n`t")[3] -split "`r`n")[0] 

, 그것은 아주 길고 매우 -split에 의존하고있다 : 순간

나는 우리를 위해 그렇게하려면 다음 코드를했다. 날짜를 검색하는 쉬운 방법이 있습니까? Select-String 또는 Regex 또는 무엇인가?

전자 메일의 테이블 형식은 사용자가 HTML 표의 날짜를 채워야 할 때와 항상 동일합니다. 그래서 우리는 그 테이블을 읽을 수 있어야합니다. 아래 예에서 결과는 01/08/2016입니다. 이러한 전자 메일의

예 :

Date added below 



From: GBR Service Desk 
Sent: Wendesday 29 juni 2016 7:00 
To: Bond, James (London) GBR 
Subject: REMINDER Expiring user: 
Importance: High 



Dear James 

This is a reminder e-mail to inform you that the following Windows user account will expire soon: 

User name 

    Logon name 

    End date 

    New end date 


Smith, Jobn (Manchester) GBR 

    jent 

    01/07/2016 

    01/08/2016 



Because you are registered as the manager of this user, we would like to ask you to verify if this account is still nee 
ded after its end date. More text... 

Yours sincerely 

는 당신의 도움을 주셔서 감사합니다.

답변

2

당신은 마지막 날짜와 같은 패턴을 찾아 선택 Select-String을 사용할 수 있습니다 : 정말 좋은 팁입니다

$EndDate = ($Mail.Body.Text |Select-String '\d{2}/\d{2}/\d{4}' -AllMatches).Matches[-1].Value 
+0

을! 고마워요. Mathias :)하지만 가끔은 "8 augustus"와 같은 말을 사용합니다. 이 경우에 나는 그것을 가질 필요가 있습니다. – DarkLite1

+0

@ DarkLite1 : 몇 가지 형식/인간 언어를 지원할 예정입니까? 질문 본문에 추가하십시오. –

+0

동의 함, 해결 됨으로 표시합니다. – DarkLite1

관련 문제