0
我會第一個承認我不是最好的正則表達式作家。我試圖在PowerShell中解析日誌文件。日誌文件以日期時間戳開始,可以是多行。一個例子如下:PowerShell中的正則表達式lookahead行爲怪異
2017-01-10T17:52:24.224-05:00 DEBUG (0EC3-018C) < ThisIsAClassName> [blah] log lines are here
this is an addition to the previous line
So is this at 2017-01
2017-01-10T17:52:26.224-05:00 DEBUG (0EC3-018C) < ThisIsADiffClassName> [blah] log lines are here
我的正則表達式看起來像這樣
Timestamp = "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}"
Anything = "[.|\w]"
NegativeLookahead = "(?!(" + Timestamp + "))"
FullRegex = Timestamp + Anything + NegativeLookahead
這使我完全投入。我做錯了什麼是爲了按時間戳分行?
你必須*匹配*?你可以用'「(?m)^(?=」+ Timestamp +「)分割」' –
'。[。| \ w]'看起來不對,它不匹配「任何東西」,它只匹配單詞字符,點符號,文字管道符號。 – wOxxOm
而且只有一次。 –