2010-04-28 5 views
6

내가이 정규식이 그룹의 대표 "NOT"로 :정규식은

<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s([\w\/\.\-]*)(.*) 

내가하고 싶은 것은 반환하는 것입니다 (일치하지 않음) 세 번째 그룹은 "MSWinEventLog"과 "일치"리턴 할 경우 FALSE 나머지는.

<166>Apr 28 10:46:34 AMC the remaining phrase 
<11>Apr 28 10:46:34 MSWinEventLog the remaining phrase 
<170>Apr 28 10:46:34 Avantail the remaining phrase 
<171>Apr 28 10:46:34 Avantail the remaining phrase 
<172>Apr 28 10:46:34 AMC the remaining phrase 
<173>Apr 28 10:46:34 AMC the remaining phrase 
<174>Apr 28 10:46:34 Avantail the remaining phrase 
<175>Apr 28 10:46:34 AMC the remaining phrase 
<176>Apr 28 10:46:34 AMC the remaining phrase 
<177>Apr 28 10:46:34 Avantail the remaining phrase 
<178>Apr 28 10:46:34 AMC the remaining phrase 
<179>Apr 28 10:46:34 Avantail the remaining phrase 
<180>Apr 28 10:46:34 Avantail the remaining phrase 

어떻게 정규식 그룹 ([\w\/\.\-]*)에서 "하지 'MSWinEventLog'"를 넣어?

참고 :
는 위

답변

8
<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s(?!MSWinEventLog)([\w\/\.\-]*)(.*) 

negative lookahead "일치하지 않는"반환해야 두 번째 문구 (여기서는 '(?!MSWinEventLog)')가 충분해야한다 :

부정적 예측이 필수적이다 뭔가가 뒤따라서 뭔가 일치하고 싶다면.
문자 클래스를 설명 할 때, 나는 왜 부정문 character class을 사용하여 "q"와 "u"가 일치하지 않는지 설명했습니다. 부정적인 선견자는 해결책을 제공합니다 : q(?!u).

+0

하하 이것은 내가 원하는 정확한 답변입니다. 어쨌든 고맙습니다. –

1

당신은 부정적 예측으로 작업을 수행 할 수 있습니다

<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s(?!MSWinEventLog)([\w\/.-])(.) 
            ----------------- 

(?!MSWinEventLog)즉시에 의해 "MSWinEventLog를"일치 식을 따르지 않을 경우에만 일치합니다.

+0

이것 역시 정확합니다. 감사 –