Powershell
查找帶有下劃線或破折號的小寫字母序列的腳本
我是在powershell中編寫腳本的新手,甚至更多的是正則表達式,請幫助實現。
例子:
PS > .\test.ps1 "A Balrog is a powerful fictional monster in Middle-earth." return: Middle-earth
或者
PS >.\test.ps1 "The symbol underscore, also called low_line or low dash." return: low_line
當然我試圖找到解決這個問題的方法,這是我的解決方案:
#$data = $args[0] $p = '\w*[-_]\w*' Select-String -Path .\content.txt -Pattern $p | % {$_ -match $p; $matches.Value} Write-Output $matches
============================================ 更新:找到解決方案
$data = $args[0] $pattern = '\w*[-_]\w*' $matches = [regex]::Matches($data, $pattern).Value Write-Output $matches