使用 PowerShell 提取子字符串 [英] Extract a substring using PowerShell
本文介绍了使用 PowerShell 提取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 PowerShell 提取子字符串?
How can I extract a substring using PowerShell?
我有这个字符串...
"-----start-------Hello World------end-------"
我必须提取...
Hello World
最好的方法是什么?
推荐答案
-match
运算符测试一个正则表达式,将它与魔术变量 $matches
结合起来得到你的结果
The -match
operator tests a regex, combine it with the magic variable $matches
to get your result
PS C:\> $x = "----start----Hello World----end----"
PS C:\> $x -match "----start----(?<content>.*)----end----"
True
PS C:\> $matches['content']
Hello World
如果对 regex-y 有疑问,请查看此站点:http://www.regular-expressions.信息
Whenever in doubt about regex-y things, check out this site: http://www.regular-expressions.info
这篇关于使用 PowerShell 提取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文