From 094e1aeca70ac47c22e6d15381139cffedb8bd76 Mon Sep 17 00:00:00 2001 From: pcnick Date: Fri, 3 Dec 2021 00:16:23 +0800 Subject: [PATCH] Get-NameRegex: exist key tag in regex string , merge into one. --- NameRegex.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NameRegex.ps1 b/NameRegex.ps1 index acdf21e..8d1f5ab 100644 --- a/NameRegex.ps1 +++ b/NameRegex.ps1 @@ -6,8 +6,11 @@ # Regex 可輸入複數個 Write-Host $Str $Regex | % { - $key = if ($_ -match "\(\?\<(.*?)\>") { $Matches[1] } - if (-not($key)) { Write-Error "$_ 沒有定義(?)" } + $key = if ($_ -match "\(\?\<(.*?)\>") { + $Matches[1] + } else { + Write-Error "$_ 沒有定義(?)" + } if ($Str -match $_ -and($key)) { $Result = @{ $key = $Matches[$key]