Python regexp multiple expressions with grouping

I’m trying to match the output given by a Modem when asked approximately the network info, it looks like this:

So I’ve two types of expressions to match, the BCCH & non BCCH. the following code is almost working:

But it seems that BOTH expressions are being matched, & not found fields left blank:

May anyone help? Why such behaviour? I’ve tried changing the order of the expressions, with no luck.


That is how capturing groups work. Since you have five of them, there will always be five parts returned.

Based on your data, I think you could simplify your regex by making the bsic part optional. That way each row would return three parts, the middle one being empty for non BCCH-Carriers.