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.
//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);
TextSelection startSelection = doc.findPattern(Pattern.compile("(?i)<start>"));