從正規表示式匹配字串獲取捕獲的組
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