List<PsiElement> (String regExpText, Project project) { String regexFileName = "A.regexp"; FileType regexFileType = FileTypeRegistry.getInstance().getFileTypeByFileName(regexFileName); if (regexFileType == UnknownFileType.INSTANCE) return Collections.emptyList(); PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(regexFileName, regexFileType, regExpText); List<PsiElement> result = null; PsiElement[] children = file.getChildren(); for (PsiElement child:children) { PsiElement[] grandChildren = child.getChildren(); if (grandChildren.length != 1) return Collections.emptyList(); // a | b, more than one branch, can not predict in current way for(PsiElement grandGrandChild:grandChildren[0].getChildren()) { if (result == null) result = new ArrayList<>(); result.add(grandGrandChild); } } return result != null ? result : Collections.emptyList(); }