我有一个,可能是简单的任务,即时尝试解决 - 迄今没有任何成功。 我想用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