I apologize if this is a repeated question, but I tried for a while and couldn't figure out what search to use.
Previously, I had a regular expression:
example_re = re.compile(r'[\(\[].*?[\)\]]')
which was supposed to capture (text that looked like this) and [this], but would also incorrectly capture text that [looked like this).
I fixed it:
example_re = re.compile(r'(\(.*?\))|(\[.*?\])')
but now, when I call example_re.findall(text), tests are breaking because where the first expression returns a list of strings, the second returns a list of tuples, whenever there is a nested expression [like (this)].
How do I fix this so that findall returns only have the outermost match?
Edit: Whoever marked this question as a duplicate really isn't helping anybody. The title of the question that this is supposedly a duplicate of is 'Python re.findall behaves weird'. How was I (or anyone else) supposed to find that? Just by virtue of the fact that I phrased the question differently makes it a non-duplicate.