In bash script, what is the easy way to extract a text pattern from a string?
For example, I want to extract X followed by 2 digits in the end of the st
X
$ foo="abcX23" $ echo "$(echo "$foo" | sed 's/.*\(X[0-9][0-9]\)$/\1/')" X23
or
if [[ "$foo" =~ X[0-9][0-9]$ ]]; then echo "${foo:$((${#foo}-3))}" fi