I'm trying to match multiple alphanumeric values (this number could vary) from a string and save them to a bash capture group array. However, I'm only getting the first match:
mystring1='<link rel="self" href="/api/clouds/1/instances/1BBBBBB"/> dsf <link rel="self" href="/api/clouds/1/instances/2AAAAAAA"/>'
regex='/instances/([A-Z0-9]+)'
[[ $mystring1 =~ $regex ]]
echo ${BASH_REMATCH[1]}
1BBBBBB
echo ${BASH_REMATCH[2]}
As you can see- it matches the first value I'm looking for, but not the second.
echo "$mystring1" | grep -oE '/instances/([A-Z0-9]+)'
?