The (bc) is an exact string, it wasn't found because the b* was greedy, but since (bc)?
is optional the match suceeded after the last 'b'.
You probably want something like this: ab*[bc]?
but this doesent make sense so probably ab*c?
. If this regex represents something more elaborate, you should post those examples.
Here is how the regex engine sees it:
Compiling REx "ab*(bc)?"
Matching REx "ab*(bc)?" against "abbbc"
0 <> <abbbc> | 1:EXACT <a>(3)
1 <a> <bbbc> | 3:STAR(6)
EXACT <b> can match 3 times out of 2147483647...
4 <abbb> <c> | 6: CURLYM[1] {0,1}(16)
4 <abbb> <c> | 10: EXACT <bc>(14)
failed...
CURLYM trying tail with matches=0...
4 <abbb> <c> | 16: END(0)
Match successful!
Compiling REx "ab*[bc]?"
Matching REx "ab*[bc]?" against "abbbc"
0 <> <abbbc> | 1:EXACT <a>(3)
1 <a> <bbbc> | 3:STAR(6)
EXACT <b> can match 3 times out of 2147483647...
4 <abbb> <c> | 6: CURLY {0,1}(19)
ANYOF[bc] can match 1 times out of 1...
5 <abbbc> <> | 19: END(0)
Match successful!