正则表达式专家的一个小问题。我有三组不同的charachters我想分开,也许你们可以帮我一点。PowerShell正则表达式过滤
$Dash = '-', '-*','*-','L-','-L' # always a dash sign with or without something else
$Blank = '', $null, ' ','*',' *', '* ', ' ' # no letter, no dash, but possible asterix
$Char = 'L', 'F','R*','*C',' C','C ' # always a letter that can be either L, F, C or R with or without asterix or space
我开始喜欢这一点,因为我不是一个正则表达式的专家,但它不工作了这么WEL并成为过于复杂:
$array | foreach {
if ($_ -match '-') {Write-Host "Dash : $_" -ForegroundColor Cyan}
elseif (($_ -eq '') -or ($_ -eq $null) -or ($_ -eq ' ') -or ($_ -like ‘`* ’)) {Write-Host "Blank : $_" -ForegroundColor Yellow}
else {Write-Host "Perm : $_" -ForegroundColor Magenta}
}
谢谢您的帮助。
试着用更多的细节来描述你以后是什么样的模式。一些关于有效和无效比赛的例子也不错。 – vonPryz 2014-10-03 11:37:32
有效的选项是'$ Dash','$ Blank'和'$ Char'中定义的选项。一切都应该失败的正则表达式。所以总共需要3个不同的正则表达式来分隔结果。我希望这更清楚。 – DarkLite1 2014-10-03 12:14:35