Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active June 22, 2020 00:21
Show Gist options
  • Save IISResetMe/d02326d8094720c975a8c4cd03ddc7f7 to your computer and use it in GitHub Desktop.
Save IISResetMe/d02326d8094720c975a8c4cd03ddc7f7 to your computer and use it in GitHub Desktop.
function Invoke-RegexTerror
{
[CmdletBinding(DefaultParameterSetName = 'ToBeOrNotToBe')]
param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[int]$Count,
[Parameter(ParameterSetName = 'ToBeOrNotToBe')]
[switch]$Shakespeare,
[Parameter(ParameterSetName = 'TheLabyrinth')]
[switch]$Kafka
)
process {
$string = 'a' * $Count
switch($PSCmdlet.ParameterSetName){
'TheLabyrinth' {
$string += 'lol'
$regex = '(a+)*$'
}
'ToBeOrNotToBe' {
$regex = 'a?' * $Count
$regex += $string
}
}
$Measurement = Measure-Command {
$string -match $regex
} |% TotalMilliseconds
[pscustomobject]@{
'How long?' = "$($Measurement -as [int])ms"
'How Many?' = $Count
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment