diff --git a/NameRegex.ps1 b/NameRegex.ps1 index 8d1f5ab..cb47255 100644 --- a/NameRegex.ps1 +++ b/NameRegex.ps1 @@ -1,7 +1,8 @@ function Get-NameRegex { param( $Str, - $Regex + $Regex, + [switch] $End ) # Regex 可輸入複數個 Write-Host $Str @@ -17,9 +18,11 @@ # 將錨定字串中的特殊字元轉換為一般字串 Anchor = $Matches[0] -replace "([\[\]\(\)])", '\$1' } - $LR = $Str -split $Result["Anchor"] - $Result.Add("L", $LR[0]) - $Result.Add("R", $LR[1]) + if (-not($End)) { + $LR = $Str -split $Result["Anchor"] + $Result.Add("L", $LR[0]) + $Result.Add("R", $LR[1]) + } else { $Result.Remove("Anchor") } $Result } } @@ -45,4 +48,11 @@ $Regex = @( #"\d" ) -$TestName | % { Get-NameRegex $_ -Regex $Regex } \ No newline at end of file +$RS1 = $TestName | % { Get-NameRegex $_ -Regex $Regex } +$RS1 + +$NameRegex = @( + "[\[\b\s](?[^\[\]]*)[\]\b\s]?$" +) + +$RS1 | % { Get-NameRegex $_["L"] -Regex $NameRegex -End } \ No newline at end of file