Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Measure-SubStringCount {
- <#
- .SYNOPSIS
- Counts occurrences of a regex pattern in the input, shows them with -Verbose
- .DESCRIPTION
- Written as an example of how the Regex MatchEvalutor can be (ab)used for good.
- #>
- [CmdletBinding()]
- param(
- [string]$Pattern,
- [Parameter(ValueFromPipeline)]$InputObject
- )
- begin {
- $script:i = 0
- }
- process {
- Write-Verbose "`e[39m$([regex]::Replace($InputObject, $Pattern, { $script:i++; "`e[91m${script:i}`e[39m" }))"
- }
- end {
- $script:i
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement