|
|
|
@ -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 } |
|
|
|
|
$RS1 = $TestName | % { Get-NameRegex $_ -Regex $Regex } |
|
|
|
|
$RS1 |
|
|
|
|
|
|
|
|
|
$NameRegex = @( |
|
|
|
|
"[\[\b\s](?<Name>[^\[\]]*)[\]\b\s]?$" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
$RS1 | % { Get-NameRegex $_["L"] -Regex $NameRegex -End } |