Browse Source

Get-NameRegex: add switch End, return Hash object include only regex TAG target.

temp1
pcnick 3 years ago
parent
commit
9496b184a9
  1. 20
      NameRegex.ps1

20
NameRegex.ps1

@ -1,7 +1,8 @@
function Get-NameRegex { function Get-NameRegex {
param( param(
$Str, $Str,
$Regex $Regex,
[switch] $End
) )
# Regex 可輸入複數個 # Regex 可輸入複數個
Write-Host $Str Write-Host $Str
@ -17,9 +18,11 @@
# 將錨定字串中的特殊字元轉換為一般字串 # 將錨定字串中的特殊字元轉換為一般字串
Anchor = $Matches[0] -replace "([\[\]\(\)])", '\$1' Anchor = $Matches[0] -replace "([\[\]\(\)])", '\$1'
} }
$LR = $Str -split $Result["Anchor"] if (-not($End)) {
$Result.Add("L", $LR[0]) $LR = $Str -split $Result["Anchor"]
$Result.Add("R", $LR[1]) $Result.Add("L", $LR[0])
$Result.Add("R", $LR[1])
} else { $Result.Remove("Anchor") }
$Result $Result
} }
} }
@ -45,4 +48,11 @@ $Regex = @(
#"\d" #"\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 }
Loading…
Cancel
Save