If I want to capture e.g. text that is either in round brackets or square brackets and use this regular expression:
\[(.+)\]|\((.+)\)
I get for the example "[test]" the results "test" and "undefined" and for "(test)" the results "undefined" and "test". How can I manage to get only "test" as result?
(This regex is only an example, my actual regex is more complex but with the same problem.)
If the specific group numbers that get captured don't matter, just the text they contain, I think the easiest thing is to just filter the match afterwards to remove the undefined groups: