string - Powershell 用通配符替换
问题描述
我想替换域字符串
“random.org” 将所有内容都放在句号之后
$newstring = $domain.replace #Not sure what else to add
我知道使用 .Replace,但不确定如何使用通配符功能以及它是如何工作的。
请给我一点帮助!
谢谢!!!
解决方案
您可以使用 PowerShell 的-replace
运算符,它使用正则表达式:
$newstring = $domain -replace '^[^.]*'
如果您想知道缺少替换字符串,这在 PowerShell 中是可选的;上面的代码在功能上与
$newstring = $domain -replace '^[^.]*', ''
推荐阅读
- bluetooth - Ubuntu 18.04 蓝牙耳机始终以 Mono 重新连接
- linux - Ansible ad-hoc 命令:如何在主机的输出中返回命令运行时?
- java - 不能在两个实例中运行相同的类
- xaml - 制作响应式框架 Xamarin 表单
- cypress - 赛普拉斯存根 GET 请求
- vue.js - 如何使用 Vue/Vuex 正确排序调用
- javascript - 在页面加载时显示引导模式
- apache-spark - 火花塞覆盖测试
- kendo-ui - Kendo UI 功能太慢:toDataURL 和 saveAsExcel
- c# - 导致文本框自动完成建议出现在代码中