I have a URL and I am trying to extract a part of the Semver. The Semver is of the format 2.x.0 (it will always be 2.x.0, if that helps). I need the x value, in the case of my example it is 15290.
I am using GNU grep. This is what I have so far:
$echo "https://example.com/repository/local/foo-bar/2.15290.0/foo_bar-2.15290.0.tar.gz" | grep -oP '(?<=[.])\d+(?=[.0])'
(?<=[.]) is a look behind. It matches, in this case, just after a period.
\d+ matches any number of digits characters.
(?=[.0]) is a look ahead. It matches, in this case, just before a period 0.
The output I am getting is
15290
15290
0
I think the 0 is getting matched because of foo_bar-2.15290.0.tar.gz. Is there a better way of doing this? I am not sure if my logic is sound.