bash parameter substitute digit one or more times -


i have version string, example

version=1.2.23b2 

i want have last part b2, tried this:

${version##*[0-9]*.[0-9]*.[0-9]*}  

my thought * mean no or many repetitions of leading pattern, in fact means character no or many times. want pattern express, digits, 1 ore more times.

* in glob pattern matches character 0 or more times.

you can use extended glob pattern here:

shopt -s extglob  echo "${version##+([0-9.])}" b2 

or else, can use regex here:

version='1.2.23b2' re='^[0-9]+.[0-9]+.[0-9]+(.+)' [[ $version =~ $re ]] && echo "${bash_rematch[1]}"  b2 

even regex should work above:

re='^[0-9.]+(.+)' 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -