This is not exactly a regex search, but it works to format / filter possible selections:
def regex_function(pattern, match): re_obj = re.search(pattern, match) if re_obj != None and len(re_obj.groups()) > 0: return re_obj.group(1) return None pdf = pdfquery.PDFQuery("tests/samples/IRS_1040A.pdf") pattern = '' pdf.extract( [ ('with_parent','LTPage[pageid=1]'), ('with_formatter', 'text'), ('year', 'LTTextLineHorizontal:contains("Form 1040A (")', lambda match: regex_function(SOME_PATTERN_HERE, match))) ])
I have not tested this following, but it may also work:
def some_regex_function_feature(): # here you could use some regex. return float(this.get('width',0)) * float(this.get('height',0)) > 40000 pdf.pq('LTPage[page_index="1"] *').filter(regex_function_filter_here) [<LTTextBoxHorizontal>, <LTRect>, <LTRect>]
source share