Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. # define the array
  2. $a = @("a.sprint-100","a.sprint-99","a.sprint-49","a.sprint-98")
  3.  
  4. # escape hard defined string in regex
  5. $escapedString = [regex]::escape(".sprint-")
  6.  
  7. # create regex which matches <AnyCharacter>.sprint-<SprintNumber>
  8. [regex]$regex = "(.+)$escapedString([0-9]{2,3})"
  9.  
  10. # process the regex on all strings and print out the sprint number
  11. $a | %{[System.Text.RegularExpressions.Regex]::Match($_, $regex)} | %{$_.Groups[2].value}
  12.  
  13. # output: 100 99 49 98
  14.  
  15. # but my sort logic doesn't work
  16. $a | %{[System.Text.RegularExpressions.Regex]::Match($_, $regex)} | Sort-Object -Property {$_.Groups[2].value} -Descending | %{$_.Groups[2].value}
  17.  
  18. # output: 99 98 49 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement