Since it's a regex, ... I did end up spending a lot of time per character on this code!
Obviously it's nice that, once you have inparens extracted, the many things you might want to test for all work consistently. I use /x/i form so that 'x' and 'X' both work. You could make that work with indexOf, but there's some extra hassle.