diff --git a/NameRegex.ps1 b/NameRegex.ps1 index cb47255..a960372 100644 --- a/NameRegex.ps1 +++ b/NameRegex.ps1 @@ -2,6 +2,7 @@ param( $Str, $Regex, + [switch] $Exclude, [switch] $End ) # Regex 可輸入複數個 @@ -25,6 +26,20 @@ } else { $Result.Remove("Anchor") } $Result } + if ($Exclude) { + $InterSB = { + if ($_["Target"] -match $_["Regex"]) { + $Result = @{ + $key = $Matches[$key] + # 將錨定字串中的特殊字元轉換為一般字串 + Anchor = $Matches[0] -replace "([\[\]\(\)])", '\$1' + } + $LR = $_["Target"] -split $Result["Anchor"] + $Result.Add("L", $LR[0]) + $Result.Add("R", $LR[1]) + } + } + } } }