Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Jul 01, 2022 6:52 pm

Using the findPattern method, you pass a pattern object that has the case-insensitive flag included. However, the search appears to ignore this flag because it only finds as written.
I am using java 11 on windows.

jmparada
 
Posts: 47
Joined: Wed May 25, 2022 7:50 am

Mon Jul 04, 2022 2:26 am

Hello,

Thank you for your inquiry.
I did an initial test with the code below, but didn't reproduce the issue you mentioned. Please test it again with the following code (attached is the test document). If the issue still exists after testing, please provide your source word document for us to investigate further. You could attach it here or send it to us via email (support@e-iceblue.com). Thanks in advance.
Code: Select all
 //Input file path
        String input = "input.docx";

        //Output file path
        String output ="output.docx";

        //Create word document
        Document document = new Document();

        //Create word document
        document.loadFromFile(input);

        //Get the second paragraph
        Section s = document.getSections().get(0);
        Paragraph para = s.getParagraphs().get(0);

        //find all matched key words with regex,not case sensitive
        Pattern c = Pattern.compile("(?i)pass\\s*");
        TextSelection[] textSelections = para.findAllPattern(c);

        //Highlight text
        for (TextSelection selection : textSelections)
        {
            selection.getAsOneRange().getCharacterFormat().setHighlightColor(new Color(255, 255, 0));
        }

        // Save to file
        document.saveToFile(output, FileFormat.Docx_2013);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Tue Jul 05, 2022 7:52 am

Below is a simple code that looks for the string "<start>" with the CASE_INSENSITIVE flag. With the attached word document, very simple, you can see how it does not find the string "<START>" which is in capital letters.

Code:

Document doc = new Document();
doc.loadFromFile("PruebaWord findpattern.docx");
TextSelection startSelection = doc.findPattern(Pattern.compile("<start>",Pattern.CASE_INSENSITIVE));

if (startSelection == null)
System.out.println("Not found");
else
System.out.println("Found: " + startSelection.getSelectedText());

jmparada
 
Posts: 47
Joined: Wed May 25, 2022 7:50 am

Tue Jul 05, 2022 8:29 am

Hello,

Thank you for your feedback.
I tested your code and did reproduce the issue you mentioned. I have logged the issue into our bug tracking system with the ticket number SPIREDOC-8098. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.
In addition, as a temporary solution,please use the code below to achieve your needs.
Code: Select all
TextSelection startSelection = doc.findPattern(Pattern.compile("(?i)<start>"));

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Tue Jul 05, 2022 2:52 pm

it works !!, thanks.

jmparada
 
Posts: 47
Joined: Wed May 25, 2022 7:50 am

Wed Jul 06, 2022 1:05 am

Hello,

You are welcome.
Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Fri Sep 30, 2022 7:49 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.Doc for Java Version:10.9.8 which fixes the issue of SPIREDOC-8098.
Welcome to test it.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc