I have an issue with bash and its regex match ability that I for now think is a bug in bash but could also be me having missed something obvious. I hope it is the latter.I have made this function in a bash script to spilt an address into fields. There is some debug output that will be removed eventually:# name number, zipfunction split_address{    local adr    adr=$4    echo $adr    local adr_regex    adr_regex=[ ]*(.*[a-z ]) ([^,][^,]*),[ ]*([^ ]*)[ ]*    [[ $adr =~ $adr_regex ]]    echo 1:X${BASH_REMATCH[1]}X    echo 2:X${BASH_REMATCH[1]%% }X    echo 3:Y${BASH_REMATCH[2]}Y    echo 4:Y${BASH_REMATCH[2]%% }Y    local x=${BASH_REMATCH[1]}    echo 5:X${x%% }X    local x=${BASH_REMATCH[1]%% }    echo 6:X${x}X    echo 7:X${x%% }X    eval $1='${BASH_REMATCH[1]%% }'    eval $2='${BASH_REMATCH[2]%% }'    eval $3='${BASH_REMATCH[3]}'}I test it like this:split_address roadname number zip   Some string   42 dp ,  1234  echo X${roadname}X Y${number}Y Z${zip}ZWhen called, I get this output:Some string 42 dp , 12341:XSome string X2:XSome string X3:Y42 dp Y4:Y42 dpY5:XSome string X6:XSome string X7:XSome stringXXSome string X Y42 dpY Z1234ZFirst note that 4 has the space shown in 3 removed. This is what I want to happen in 2 when working on 1. Notice that 5 does not get the space removed even though this happens on the variable x. This was an attempt to work around this issue.Then I tried assigning the space-removing operation to the variable x but that also failed (shown in 6). But removing spaces on x in step 7 worked even though the line is identical to 5 and the input apparently as well.Is this me doing something weird or is this a bug in bash?For reference, I am working on Ubuntu 14 LTS with bash version 4.3.11(1)-release.I see the same behavior with Cygwin-x64 with bash version 4.1.17(9-release.I have verified that the character to be removed in deed is a space (using od on both source and test-call).
Bash regex string manipulation bug
bash;regular expression;string