for a pdf page that has data that produces a text string of "hello world", that is "hello" followed by multiple whitespace and then the word world. How do I write the regular expression for your parser to match multiple whitespace between the words. I have tried many variations including those that validate correctly on reg exp checkers on the internet and nothing seems to match the multiple whitespace. If I print out the page of text and capture the exact number of whitespaces your routine finds between the two words and manually put that in the search string it still doesn't find the two strings with multiple whitespace between.
The actual string was "(word1) (word2)" with parentheses. Your text output had 11 spaces between the words. Inputting the string just given with 11 spaces and trying to search for that exactly didn't work either.
It finds just the first string (no problem), just the second string (no problem), but doesn't find the two strings with multiple whitespace.
New Information:
I have found the reason the regular expression pattern match is not working but it now raises a new issue. In order to try to debug the issue I did the following 2 things.
1)I used the Spire function page.extractText(true) returns the entire page of text with line breaks. Line 21 yields the following
(Counts) (psig) (°F) (Mcf) Mcf) (Mcf) (Btu/scf) (MMBtu)
I am trying to find the string: "(Mcf) (Btu/scf)"
2) I added the following routine ( copied from one of your examples) to print out the contents of the PdfTextFind getFinds()
private void printFindCollectionResults(PdfTextFindCollection pdftextfindcollection) throws Exception {
//
for (PdfTextFind find : pdftextfindcollection.getFinds()) {
//
System.out.println("=====================================================================");
System.out.println(" Match Text: " + find.getMatchText());
System.out.println(" Text: " + find.getSearchText());
System.out.println(" Size: " + find.getSize());
System.out.println(" Position: " + find.getPosition());
System.out.println(" The index of page which is including the searched text : " + find.getSearchPageIndex());
System.out.println(" The line that contains the searched text : " + find.getLineText());
System.out.println(" Match Text: " + find.getMatchText());
}
}
Now, if I try to find the string with the regular expression of: "\\(Mcf\\)( )+\\(Btu/scf\\)" it doesn't find it. But if I modify this to the following: "( )+\\(Btu/scf\\)" it finds it and prints out the following from your routine above:
==================================================================================
Match Text: (Btu/scf)
Text: ( )+\(Btu/scf\)
Size: com.spire.office.packages.sprthja[width=28.18225,height=6.95]
Position: Point2D.Float[401.3, 255.19]
The index of page which is including the searched text : 0
The line that contains the searched text : (Btu/scf)
Match Text: (Btu/scf)
Please note the second to the last line "The line that contains the searched text : (Btu/scf). Your find function is not finding the expression "\\(Mcf\\)( )+\\(Btu/scf\\)" because your pdftextfindcollection.getFinds() routine for some reason believes the entire line is " (Btu/scf)". It is chopping Line 21 into smaller parts. Can you clarify what is going. I have checked the full page using a hex editor and there are only spaces between the (Mcf) and the (Btu/scf) strings.
Any help you can give is appreciated.