In your second result, a
is appearing because you’ve wrapped it in a capture group ()
(parentheses).
If you want to not include it but you still require a conditional group, use a non-capturing group: (?:a)
. The questionmark-colon can be used inside any capture group and it will be omitted from the resulting list of captures.
Here’s a simple example of this in action: http://regex101.com/r/yM1vM4