从正则表达式匹配字符串获取捕获的组
a='I am a simple string with digits 1234'
pat='(.*) ([0-9]+)'
[[ "$a" =~ $pat ]]
echo "${BASH_REMATCH[0]}"
echo "${BASH_REMATCH[1]}"
echo "${BASH_REMATCH[2]}"
输出:
I am a simple string with digits 1234
I am a simple string with digits
1234