Skip to content

Commit

Permalink
Update RegexStringToSegments.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Jan 7, 2024
1 parent d5307ae commit b344a13
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions Pwsh/Regex/RegexStringToSegments.ps1
Original file line number Diff line number Diff line change
@@ -39,7 +39,8 @@ function New-Regex.SplitBySegmentSize {
[string]$Delimiter = ':',

[ArgumentCompletions('Original', 'MultiLine1', 'MultiLine2')]
[string]$RegexName = 'Original' # MultiLine2
[string]$RegexName = 'Original'
# [string]$RegexName = 'Original' # MultiLine2

)
# was: '(?<=\G..)(?!$)',':'
@@ -66,6 +67,17 @@ function New-Regex.SplitBySegmentSize {
|^
)
(?!$)
'@
$regex.MultiLine3 = @'
(?x)
(?mi)
# previous version moved delim to the start of match,
# this preserves the original end of
(?:
(?<=\G{0})
|^
)
(?!$)
'@
# $selectedRegex = $Regex.Original
# $selectedRegex = $Regex.MultiLine
@@ -210,14 +222,25 @@ function FancyName {
[ArgumentCompletions(
2, 3, 4, 10, 16
)]
[int]$Len
[int]$Len,

[Parameter(Mandatory, ValueFromPipeline)]
[object[]]$InputObject
)
$Input
begin {
[List[Object]]$Items = @()
}
process {
$Items.AddRange(@( $InputObject ))
}
end {
$Items
| % $PropertyName
| Sort-Object -Unique
| Join-String -sep $Separator -p {
$_ | FancySegment -SegmentLength $Len ''
}
}
}

hr

0 comments on commit b344a13

Please sign in to comment.