简体   繁体   English

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

[英]Get certain text in string powershell

I want to get "localhost" (or whatever text) inside this string: 我想在此字符串中获取“ localhost”(或任何文本):

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

I want a general method, like a way to reuse an expression value (like with sed in linux) 我想要一个通用方法,例如一种重用表达式值的方法(例如linux中的sed)

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

Thank you very much for any reply 非常感谢您的回复

$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