powershell - RegEx Finding multiple matches with a quantifier -
i have powershell code:
$uri = "http://charts.spotify.com/api/tracks/most_streamed/au/daily/latest" $contenttype = "application/json" $postblog = (invoke-webrequest -uri $uri).content -match 'track_name\s:\s(.*?)",' $matches[1] when run this, result:
fourfiveseconds problem is, know there more songs 1 song. , know match using, string of text "track_name" exists more once. how can change regex matches every match can find? in other words, expected output multiple matches, allowing me list songs, e.g. $matches[1], $matches[2], $matches[3], $matches[4], etc.
since using invoke-webrequest, assume using powershell v4.0. therefore, can use convertfrom-json on data received , iterate on it, instead of using regex solution:
$uri = "http://charts.spotify.com/api/tracks/most_streamed/au/daily/latest" $contenttype = "application/json" $postblog = (invoke-webrequest -uri $uri).content | convertfrom-json now, entire tracks data available inside $postblog.tracks array.
iterate on them track_urls:
foreach( $track in $postblog.tracks ) { write-output $track.track_url } edit
apparently, can use:
write-output $postblog.tracks.track_url instead of foreach code-block. @petseral :)
Comments
Post a Comment