Bash regular expression groups not working

Viewed 4014

I am trying to pattern match in my bash script but for some reason the BASH_REMATCH var is not being set with my groups.

Code below:

if [[ "SYSENV01" =~ ^(SYS)(ENV)(01)$ ]]; then
    echo ${BASH_REMATCH[0]}        
    echo ${BASH_REMATCH[1]}
    echo ${BASH_REMATCH[2]}
fi

Weirdly this prints out SYSENV01 then 2 empty lines to the command line - so it must be matching; however, the groups do not appear.

Any ideas? This has had me in circles for ages.

1 Answers
Related