Regex pattern is not matching

Hi,

I have to find and replace some words from the document using regex. I am adding the regex as a pattern in replace function and replacing it inside the IReplacing implementation. I am adding the code below,

Pattern pattern = Pattern.compile("(\\|[a-zA-Z]+\\s*(\\{[a-zA-Z0-9\\(\\[\\+\\,\\-\\/\\)\\=\\:\\.\\'\\’\\\\\\&\\s*\\]]*\\})*\\|)", Pattern.CASE_INSENSITIVE);
FindReplaceOptions findReplaceOptions = new FindReplaceOptions(FindReplaceDirection.BACKWARD);
findReplaceOptions.setReplacingCallback(findAndReplaceCallBack);

NodeCollection<Paragraph> paragraphList = asposeUtil.getParagraphNodes(inputstream, document);
if (paragraphList != null) {
    for (Paragraph paragraph : paragraphList) {
        Range paragraphRange = paragraph.getRange();
        try {
            paragraphRange.replace(pattern, Constants.EMPTY_STRING, findReplaceOptions);
        } catch (Exception e) {
            throw new CimplyfiveException("Exception occured during token replacement : ", e);
        }

    }
}

It finds and replaces all the matches except this one |agTbl{sl(S. No)[10]}|. While testing in an online regex compiler, this pattern as well matching.

Please help me to figure out the issue

Thank you

@Gptrnt Could you please attach your sample document here for testing? I have tested with the following code:

Pattern pattern = Pattern.compile("(\\|[a-zA-Z]+\\s*(\\{[a-zA-Z0-9\\(\\[\\+\\,\\-\\/\\)\\=\\:\\.\\'\\’\\\\\\&\\s*\\]]*\\})*\\|)", Pattern.CASE_INSENSITIVE);
FindReplaceOptions findReplaceOptions = new FindReplaceOptions(FindReplaceDirection.BACKWARD);
        
Document doc = new Document("C:\\Temp\\in.docx");
doc.getRange().replace(pattern, "This is replacement", findReplaceOptions);
doc.save("C:\\temp\\out.docx");

And the following simple document: in.docx (12.7 KB)
The placeholder is properly replaced: out.docx (10.3 KB)