The problem is that you have an alternation with a capturing group on each side:
(regex1)|(regex2)
The matcher will start and search for a match using the first alternation; if not found, it will try the second alternation.
However, those are still two groups, and only one will match. The one which will not match will return null, and this is what happens to you here.
You therefore need to test both groups; since you have a match, at least one will not be null.