RegExpGroup (int index, PsiFile file) { List<RegExpGroup> groups = SyntaxTraverser.psiTraverser(file) .filter(RegExpGroup.class) .filter(RegExpGroup::isCapturing) .toList(); return index <= groups.size() ? groups.get(groups.size() - index) : null; }