|
|
|
@ -5,49 +5,46 @@
|
|
|
|
|
$Exclude, |
|
|
|
|
[switch] $End |
|
|
|
|
) |
|
|
|
|
# Regex 可輸入複數個 |
|
|
|
|
Write-Host $Str |
|
|
|
|
$Regex | % { |
|
|
|
|
$key = if ($_ -match "\(\?\<(.*?)\>") { |
|
|
|
|
$Matches[1] |
|
|
|
|
} else { |
|
|
|
|
Write-Error "$_ 沒有定義(?<TAG>)" |
|
|
|
|
} |
|
|
|
|
if ($Str -match $_ -and($key)) { |
|
|
|
|
$Result = @{ |
|
|
|
|
$key = $Matches[$key] |
|
|
|
|
# 將錨定字串中的特殊字元轉換為一般字串 |
|
|
|
|
Anchor = $Matches[0] -replace "([\[\]\(\)])", '\$1' |
|
|
|
|
# 查詢 Regex 字串中定義的 TAG,並將其作為 Scriptblock |
|
|
|
|
$Keyfind = { |
|
|
|
|
process{ |
|
|
|
|
if ($_ -match "\(\?\<(.*?)\>") { |
|
|
|
|
$Matches[1] |
|
|
|
|
} else { |
|
|
|
|
Write-Error "$_ 沒有定義(?<TAG>)" |
|
|
|
|
} |
|
|
|
|
if (-not($End)) { |
|
|
|
|
$LR = $Str -split $Result["Anchor"] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
$InnerScrip = { |
|
|
|
|
# 取用管線傳入的 hash 進行 match |
|
|
|
|
process { |
|
|
|
|
$Key = $_["Regex"] | &$Keyfind |
|
|
|
|
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]) |
|
|
|
|
} else { $Result.Remove("Anchor") } |
|
|
|
|
$Result |
|
|
|
|
} |
|
|
|
|
if ($Exclude) { |
|
|
|
|
# 以 hash 送入 scriptblock |
|
|
|
|
$InterSB = { |
|
|
|
|
# 取用管線傳入的 hash 進行 match |
|
|
|
|
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]) |
|
|
|
|
# 對 Matches 結果,比對 $Exclude |
|
|
|
|
if ($Result["Anchor"] -match $Exclude) { |
|
|
|
|
$Result.Add("Regex", $_["Regex"]) |
|
|
|
|
$Result.Add("Target", $Result["L"]) |
|
|
|
|
} |
|
|
|
|
# 對 Anchor 結果,以 $Exclude 進行比對,符合則加入剩餘字串重新 match |
|
|
|
|
if ($Exclude -and($Result["Anchor"] -match $Exclude)) { |
|
|
|
|
$Result.Add("Regex", $_["Regex"]) |
|
|
|
|
$Result.Add("Target", $Result["L"]) |
|
|
|
|
return $Result | &$InnerScrip |
|
|
|
|
} |
|
|
|
|
# 結尾模式,僅輸出符合 TAGKEY 的 hash |
|
|
|
|
if ($End) { return @{ $Key = $Result[$Key] } } else { return $Result } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Write-Host $Str |
|
|
|
|
# Regex 可輸入複數個 |
|
|
|
|
$Regex | % { @{ Target = $Str; Regex = $_; } } | &$InnerScrip |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$Pathes = @( |
|
|
|
@ -77,51 +74,22 @@ $NameRegex = @(
|
|
|
|
|
"[\[\b\s](?<Name>[^\[\]]*)[\]\b\s]?$" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
$RS1 | % { Get-NameRegex $_["L"] -Regex $NameRegex -End } |
|
|
|
|
$RS1 | % { Get-NameRegex $_["L"] -Regex $NameRegex -Exclude "(BD|DVD|HDTV)RIP" -End } |
|
|
|
|
|
|
|
|
|
#if ($Exclude) { |
|
|
|
|
$TestName | % { Get-NameRegex $_ -Regex $Regex } |
|
|
|
|
$TestName | % { Get-NameRegex $_ -Regex $Regex } | % { $(Get-NameRegex $_["L"] -Regex $NameRegex -Exclude "(BD|DVD|HDTV)RIP" -End) + $_ } |
|
|
|
|
|
|
|
|
|
$Keyfind = { |
|
|
|
|
process{ |
|
|
|
|
if ($_ -match "\(\?\<(.*?)\>") { |
|
|
|
|
$Matches[1] |
|
|
|
|
} else { |
|
|
|
|
Write-Error "$_ 沒有定義(?<TAG>)" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
# 以 hash 送入 scriptblock |
|
|
|
|
$InterSB = { |
|
|
|
|
# 取用管線傳入的 hash 進行 match |
|
|
|
|
param($Hobj, $Target, $Regex, $Key) |
|
|
|
|
Write-Host $hash, $_ |
|
|
|
|
process { |
|
|
|
|
if ($Hobj) { $hash = $Hobj } else { $hash = $_ } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($hash) { |
|
|
|
|
$Target = $hash["Target"] |
|
|
|
|
$Regex = $hash["Regex"] |
|
|
|
|
if ($hash.ContainsKey("Key")) { $Key = $hash["Key"] } |
|
|
|
|
} |
|
|
|
|
if (-not($Key)) { $Key = $Regex | &$Keyfind } |
|
|
|
|
if ($Target -match $Regex) { |
|
|
|
|
$Result = @{ |
|
|
|
|
$key = $Matches[$key] |
|
|
|
|
# 將錨定字串中的特殊字元轉換為一般字串 |
|
|
|
|
Anchor = $Matches[0] -replace "([\[\]\(\)])", '\$1' |
|
|
|
|
} |
|
|
|
|
$LR = $hash["Target"] -split $Result["Anchor"] |
|
|
|
|
$Result.Add("L", $LR[0]) |
|
|
|
|
$Result.Add("R", $LR[1]) |
|
|
|
|
# 對 Matches 結果,比對 $Exclude |
|
|
|
|
if ($Result["Anchor"] -match $Exclude) { |
|
|
|
|
$Result.Add("Regex", $hash["Regex"]) |
|
|
|
|
$Result.Add("Target", $Result["L"]) |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
} |
|
|
|
|
$D1 = $Str | % { Get-NameRegex $_ -Regex $Regex } |
|
|
|
|
|
|
|
|
|
$Keyfind = { |
|
|
|
|
process{ |
|
|
|
|
if ($_ -match "\(\?\<(.*?)\>") { |
|
|
|
|
$Matches[1] |
|
|
|
|
} else { |
|
|
|
|
Write-Error "$_ 沒有定義(?<TAG>)" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$InterSB2 = { |
|
|
|
|
# 取用管線傳入的 hash 進行 match |
|
|
|
|
process { |
|
|
|
@ -144,19 +112,21 @@ $RS1 | % { Get-NameRegex $_["L"] -Regex $NameRegex -End }
|
|
|
|
|
$Result |
|
|
|
|
}} |
|
|
|
|
} |
|
|
|
|
# } |
|
|
|
|
|
|
|
|
|
$D1 = $Str | % { Get-NameRegex $_ -Regex $Regex } |
|
|
|
|
$D2 = @{ |
|
|
|
|
Target = $D1["L"] |
|
|
|
|
Regex = $NameRegex[0] |
|
|
|
|
#Exclude = "BDrip" |
|
|
|
|
Exclude = "BDrip" |
|
|
|
|
} |
|
|
|
|
$D2 |
|
|
|
|
|
|
|
|
|
$eeww = @("Exclude", "Key") |
|
|
|
|
$D2.Remove($eeww) |
|
|
|
|
$eeww | % { $D2.Remove($_) } |
|
|
|
|
|
|
|
|
|
$D2["Target"] |
|
|
|
|
$wee = $D2["Regex"] | &$Keyfind |
|
|
|
|
|
|
|
|
|
$Exclude = "1" |
|
|
|
|
$D2["Target"] |
|
|
|
|
$D2 | &$InterSB2 |
|
|
|
|
$D2 | &$InterSB2 |
|
|
|
|