Skip to content

Commit

Permalink
regex demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed May 16, 2024
1 parent 1b2c313 commit ac5a9aa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Pwsh/Regex/Match-Captures-Groups-Collections.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

$single = [regex]::Matches('a9', '9')

$few = [regex]::Matches('sda324r32 d23 ew', '(?<Token>.+)')
$few.Captures.Groups | Ft
$few.Groups | Ft

$single[0].Groups | Ft ; hr ;
$single[0].Captures.groups | Ft
hr -fg magenta
$few[0].Groups | Ft ; hr ;
$few[0].Captures.groups | Ft

$single | %{ $_.Captures[0].Groups[0].gettype() } # -is <Match : Group>
$single | %{ $_.Captures[0].Groups[999].gettype() } # -is <Group : Capture>
$single | %{ $_.Captures[0].Groups.count } # but the length is 1

$few | %{ $_.Captures[0].Groups[0].gettype() } # -is <Match : Group>
$few | %{ $_.Captures[0].Groups[999].gettype() } # -is <Group : Capture>
$few | %{ $_.Captures[0].Groups.count } # but the length is 2

$few | %{ $Null -eq $_.Captures[1] } # Is always true null for >= 1

0 comments on commit ac5a9aa

Please sign in to comment.