Views/Irregular.RegEx.Output.html.view.ps1
[PSTypeName('Irregular.Regex.Output')] param(<#$_ = $(Show-Regex -Pattern \d+ -Match 123abc123)#>) $fg = if ($exprWorked) { "#00ff00" } else { "#ff0000" } $groupsByName = $out.Matches | Select-Object -ExpandProperty Groups | Where-Object { $_.Success -and $_.Length } | Group-Object Name $groupNames = @($groupsByName | Select-Object -ExpandProperty Name) $groupRanges = @{} foreach ($g in $groupsByName) { $r = @() $r+=foreach ($_ in $g.Group) { $_.Index..($_.Index + ($_.Length - 1)) } $groupRanges[$g.Name] = $r } $highlightChars = $out.Matches | ForEach-Object { $_.Index..($_.Index + ($_.Length - 1)) } | Select-Object -Unique $highlightedOut = @(for ($i = 0; $i -lt $out.Text.Length; $i++) { $enc = [Web.HttpUtility]::HtmlEncode($out.Text[$i]) $classes = @(foreach ($kv in $groupRanges.GetEnumerator()) { if ($kv.Value -contains $i) { "match$($kv.Key)" } }) if ($classes) { "<span class='$($classes -join ' ') char'>$enc</span>" } else { "<span class='char'>$enc</span>" } |