ModCommand (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); if (!(element instanceof RegExpBranch)) { return ModCommand.nop(); } final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(element.getProject()); final TextRange range = descriptor.getTextRangeInElement(); final StringBuilder text = new StringBuilder(); PsiElement child = element.getFirstChild(); boolean inserted = false; while (child != null) { if (!range.contains(child.getStartOffsetInParent())) { text.append(injectedLanguageManager.getUnescapedText(child)); } else if (!inserted) { text.append(" {").append(myCount).append('}'); inserted = true; } child = child.getNextSibling(); } return ModCommand.psiUpdate(element, e -> RegExpReplacementUtil.replaceInContext(e, text.toString())); }