Skip to content

Instantly share code, notes, and snippets.

@SeidChr
Last active October 4, 2022 08:36
Show Gist options
  • Save SeidChr/5f0c0fd4097a52bfeea24866547f9b6b to your computer and use it in GitHub Desktop.
Save SeidChr/5f0c0fd4097a52bfeea24866547f9b6b to your computer and use it in GitHub Desktop.
# generate regex match groups from arrays
function ContGroup {
param([object[]]$Source, [int]$GroupSize)
0..($Source.Length-$GroupSize) |% { $Source | Select -Skip $_ -First $GroupSize | Join-String }
}
# $ ContGroup -Source (1..9 + 0) -GroupSize 4 | Join-String -Separator '|'
# 1234|2345|3456|4567|5678|6789|7890
# $ ContGroup -Source ('a'..'z') -GroupSize 3 | Join-String -Separator '|'
# abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz
# https://stackoverflow.com/q/73943221/1280354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment