Question in short
Given a string, how to retrieve several sub-strings given a regex?
echo "hello world 15 42" | grep -P ".*([0-9]+) ([0-9]+)";
This unfortunately return the full matching string, not the 15 and 42 separately. Ideally some variable would recover both of them so I could use them:
echo "First: $0, Second: $1"; # echo is only an example
More of the context
For an install script, it needs to download the relevant file from an URL (with wget), however, the specific file name is unknown, so the script need to first download the index.html to extract file-names, extract the version numbers and re-construct the full URL.
wget 2>/dev/null -O - http://...../directory/ | grep -P "<a href=.... wget "http://..../directory/file-$1-revision-$2.gz" -O downloaded.gz