我有一個,可能是簡單的任務,即時嘗試解決 - 迄今沒有任何成功。 我想用powershell來解析和匹配一個字符串到變量中。 字符串的形式正則表達式和powershell
"Message
-------
RECORDING XYZ started recording on 2016-11-08 19:58:03 and stopped on 2016-11-08 20:33:00 as scheduled."
的,我希望它產生三個變量$標題= 「錄製XYZ」,$ START_TIME = 「2016年11月8日19時58分03秒」,$ STOP_TIME =「 2016-11-08 20:33:00「。
是正則表達式的路還是powershell有更簡單的函數?我一直在看 - 分裂和 - 匹配前。
請問有沒有人有時間給我一隻手? 問候
編輯:
馬蒂亞斯的回答使我這個解決方案
$text = "Message
-------
RECORDING XYZ started recording on 2016-11-08 19:58:03 and stopped on 2016-11-08 20:33:00 as scheduled."
$lines = $text -split "\n"
$lines[2] -match "^(.+) started recording on (.+) and stopped on (.+) as scheduled."
Write-Output $Matches[1]
簡單,但它的工作原理
東西=「消息 ------- 錄製XYZ開始記錄上2016-11 -08 19:58:03並在2016-11-08 20:33:00按計劃停止。「$ a = $ text -split」\ n「 $ b = $ a -match」^(。+)\按照計劃在\ s(。+)上開始錄製並停在(。+)上。「$ title = $ t [1] – Jiinxy