首页 > 解决方案 > Powershell 用通配符替换

问题描述

我想替换域字符串

“random.org” 将所有内容都放在句号之后

$newstring = $domain.replace #Not sure what else to add

我知道使用 .Replace,但不确定如何使用通配符功能以及它是如何工作的。

请给我一点帮助!

谢谢!!!

标签: stringpowershellreplace

解决方案


您可以使用 PowerShell 的-replace运算符,它使用正则表达式:

$newstring = $domain -replace '^[^.]*'

如果您想知道缺少替换字符串,这在 PowerShell 中是可选的;上面的代码在功能上与

$newstring = $domain -replace '^[^.]*', ''

推荐阅读