Guest User

Untitled

a guest
Oct 14th, 2019
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Measure-SubStringCount {
  2. <#
  3. .SYNOPSIS
  4. Counts occurrences of a regex pattern in the input, shows them with -Verbose
  5. .DESCRIPTION
  6. Written as an example of how the Regex MatchEvalutor can be (ab)used for good.
  7. #>
  8. [CmdletBinding()]
  9. param(
  10. [string]$Pattern,
  11. [Parameter(ValueFromPipeline)]$InputObject
  12. )
  13. begin {
  14. $script:i = 0
  15. }
  16. process {
  17. Write-Verbose "`e[39m$([regex]::Replace($InputObject, $Pattern, { $script:i++; "`e[91m${script:i}`e[39m" }))"
  18. }
  19. end {
  20. $script:i
  21. }
  22. }
RAW Paste Data