Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # define the array
- $a = @("a.sprint-100","a.sprint-99","a.sprint-49","a.sprint-98")
- # escape hard defined string in regex
- $escapedString = [regex]::escape(".sprint-")
- # create regex which matches <AnyCharacter>.sprint-<SprintNumber>
- [regex]$regex = "(.+)$escapedString([0-9]{2,3})"
- # process the regex on all strings and print out the sprint number
- $a | %{[System.Text.RegularExpressions.Regex]::Match($_, $regex)} | %{$_.Groups[2].value}
- # output: 100 99 49 98
- # but my sort logic doesn't work
- $a | %{[System.Text.RegularExpressions.Regex]::Match($_, $regex)} | Sort-Object -Property {$_.Groups[2].value} -Descending | %{$_.Groups[2].value}
- # output: 99 98 49 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement