But notice that here (A|) is followed by an extra A in the pattern:
s=AA; echo ${s#(A|)A}
Since the first "A" of s=AA matches the "A" in "(A|)", the matcher should proceed and try to match the second "A" of s=AA to the second "A" of the pattern. Since that succeeds too, the expansion should return the empty string. But here somehow the pattern matcher backtracks to find out that s=AA also matches the second alternative of "(A|)" and that then the remaining "AA" still matches the second "A" of the pattern, which leads to a shorter match and to the printing of "A".
Philippe