Hi,
I’m new to this lark and struggling a little. I can successfully search a PDF for a specific string, but I’m struggling to get the regex option to work. The documentation implies that if I set the regex option in “withOptions” it uses the search string as a regex expression.
But I get nothing.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
# Test PDF
# https://docs.oracle.com/en/database/oracle/oracle-database/19/cncpt/database-concepts.pdf
on searchPDFnoRegex:posixPath forString:searchString
set theURL to current application's class "NSURL"'s fileURLWithPath:posixPath
set thePDF to current application's PDFDocument's alloc()'s initWithURL:theURL
set theMatches to (thePDF's findString:searchString withOptions:0)
log ("Number of Hits " & (count of theMatches))
end searchPDFnoRegex:forString:
on searchPDFwithRegex:posixPath forString:searchString
set theURL to current application's class "NSURL"'s fileURLWithPath:posixPath
set thePDF to current application's PDFDocument's alloc()'s initWithURL:theURL
set theMatches to (thePDF's findString:searchString withOptions:((current application's NSRegularExpressionSearch)))
log ("Number of Hits " & (count of theMatches))
end searchPDFwithRegex:forString:
set theFile to "/Users/home/database-concepts.pdf"
log ("Regex option not set")
my searchPDFnoRegex:theFile forString:"Oracle"
#Reports 2698 hits
log ("Regex option set, but no wildcards")
my searchPDFwithRegex:theFile forString:"Oracle"
#Reports 2698 hits
log ("Regex option set, with wildcards")
my searchPDFwithRegex:theFile forString:"Oracl."
#Reports 0 hits
Please could some kind sole suggest what I might be doing wrong ?
Thanks