我在让正则表达式提取字符串的一部分时遇到问题,我看不出我做错了什么。
字符串:
Backup job DailyBackupToNAS completed successfully. Destination: Network location Start time: 01/05/2013 05:00:28 End time: 01/05/2013 05:39:13 Duration: 00:38:45.5875346
编码:
$destinationregex = "Destination: (.*)Start time:"
If ($message -match $destinationregex)
{
$destination = $matches[1]
}
我正在尝试提取文本网络位置
任何指针将不胜感激!
根据要求提供更全面的代码 $events = get-eventlog application -source BackupAssist -newest 50
Foreach ($event in $events)
{
$message = $event.message
$destinationregex = "Destination: (.*)Start time:"
If ($message -match $destinationregex)
{
$destination = $matches[1]
}
Else
{
$destination = "Unknown"
}
Write.Host $destination
}