首页 > 解决方案 > Powershell 装饰线

问题描述

我有以下字符串:

Account name:            abc.def

例如,其中 abc.def 是用户名John.doe
我需要修剪这个字符串,只留下用户名,例如abc.def

无论我尝试什么select-string-match没有让我到达那里。

标签: powershell

解决方案


您可以删除直到并包括:with的所有内容-replace,然后让我们String.Trim()处理空格:

PS ~> $string = "Account name:            abc.def"
PS ~> ($string -replace '^.*?:').Trim()
abc.def

推荐阅读