Powershell Regex换行符\ n

时间:2018-09-07 11:32:59

标签: regex xml powershell powershell-v3.0

我想在Powershell中使用RegEx脚本从XML文件中获取名字和名字。在RegEx脚本中是\ n。我测试了一下,如果我想匹配XML中的换行符并写\ n,那就不再匹配了。我也尝试过\ r \ n,但这也行不通。


$search = "Sepp"
$path = "D:\example.xml"
$regex = "<firstname>$search<\/firstname>"
$result = select-string -Path $path -Pattern $regex - 
AllMatches |  ForEach-Object { $_.Matches } | ForEach-Object 
{ $_.Value }
Write-Host $result

比赛:Sepp


$search = "Sepp"
$path = "D:\xml\hey.xml"
$regex = "<firstname>$search<\/firstname>\n.*"
$result = select-string -Path $path -Pattern $regex -AllMatches |  ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }
Write-Host $result

匹配:没有| $ result -eq $ null


我该如何解决? 谢谢

0 个答案:

没有答案