From c06c9d51fd2fe1aaa429cf1fedb1a232facf9947 Mon Sep 17 00:00:00 2001 From: pcnick Date: Sat, 4 Dec 2021 12:00:20 +0800 Subject: [PATCH] Get-NameRegex: feature Exclude, test scriptblock for recurse --- NameRegex.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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]) + } + } + } } }