Reputation: 5856
I'm trying to extract part of the string in elements of an array, and create a new array with these extractions.
[
"local/binaries/app-2.21.0.tar.gz",
"local/binaries/app-2.20.0.tar.gz",
"local/binaries/app-2.19.1.tar.gz",
"local/binaries/app-2.19.0.tar.gz",
"local/binaries/app-2.18.0.tar.gz"
]
Desired output
[
"app-2.21.0",
"app-2.20.0",
"app-2.19.1",
"app-2.19.0",
"app-2.18.0"
]
Upvotes: 1
Views: 1044
Reputation: 2422
You can use jq's capture
function with regular expressions.
jq '[.[] | capture("(?<captured>app-[0-9]+\\.[0-9]+\\.[0-9]+)") | .[]]'
Documentation: https://stedolan.github.io/jq/manual/#RegularexpressionsPCRE
Upvotes: 4