IN NS google-public-dns-a.google.com. ; in the domain
从上面一行,我想以下面一行的格式提取和显示单词。
NS google-public-dns-a.google.com.
如何使用PowerShell实现此目的?请指教。
我的代码如下
ForEach-Object { $recordtype += ($_ -split " " | Select-String -SimpleMatch ("NS","SOA","A","MX") -List ) };
答案 0 :(得分:0)
您可以使用RegEx替换运算符-replace
。例如,-replace '^.*?(NS|SOA|A|MX)(.*);.*','$1$2'
将排除NS,SOA,A和MX之前以及分号后的字符。
ForEach-Object { $recordtype += ($_ -split " " | Select-String -SimpleMatch ("NS","SOA","A","MX") -List ) -replace '^.*?(NS|SOA|A|MX)(.*?);.*','$1$2' };