我想在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
$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
我该如何解决? 谢谢