繁体   English   中英

在字符串powershell中获取某些文本

[英]Get certain text in string powershell

我想在此字符串中获取“ localhost”(或任何文本):

XML-Execute-Result: <host>localhost</host>

我想要一个通用方法,例如一种重用表达式值的方法(例如linux中的sed)

sed 's/*[0-9]$/\$&/'

非常感谢您的回复

$text = "XML-Execute-Result: <host>localhost</host>"
if ($text -match "\<host\>(?<host>.*?)\</host\>")
{
    $myhost = $matches.host
}
PS> if ($text -match "<host>(.*?)</host>") {$matches[1]}
localhost

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM