2012-06-26 36 views
0

我試圖創建一個正則表達式來解析Windows日誌事件中的一個句子的一部分。解析句子部分的正則表達式

舉個例子,EVENTCODE = 7035生成以下內容:

The Network Location Awareness (NLA) service was.....sent a start 
The Network Connection service was....sent a stop 
The HTTP service was....sent a start 
The HTTP service was....sent a stop 
etc... 

我想是和解析出來,只是「將」,「服務」,並在作品開始或停止的信息。

這樣我就可以建立一個服務列表,開始或停止。

有關這方面的想法?

+2

語言是什麼? – nhahtdh

+0

我實際上試圖將它與Splunk一起使用。因此,它將是,EventCode = 7035 |重複消息|正則表達式..... – mrwh1t3

回答

0

我使用了Splunk Interactive字段提取器。

使用下面的搜索正則表達式爲

對於服務型

| rex "(?i)^The\s(?P<ServiceType>[^ ]+)\sservice" 

對於服務狀態

| rex "(?i)sent\sa\s(?P<ServiceStatus>[^ ]+)" 

使用領域的 「服務類型」 和 「ServiceStaus」 作進一步的結果和圖表。

\ s是爲空間或可以使用實際空間「」。

0

在Python(從問題的文本是s)的一個例子:

re.findall("(The.*?service).*?(start|stop)",s) 

給出:

[('The Network Location Awareness (NLA) service', 'start'), 
('The Network Connection service', 'stop'), 
('The HTTP service', 'start'), ('The HTTP service', 'stop')] 
0

我想你可以用這個正則表達式中提取數據:

The (.*?) service .*? (start|stop) 

數據正在捕獲組1和2.