解決 pdfgrep 正則表示式搜尋時遇到 PCRE support disabled at compile time!

pdfgrep 可利用命令列視窗 (或稱為終端機) 搜尋多個 PDF 檔案內文。Mac 安裝後,啟用正則表示式 (Regular expression, PCRE) 選項,搜尋時遇到「pdfgrep: PCRE support disabled at compile time!」解決方式是加上「--with-pcre」重新安裝。




更新pdfgrep 版本 2.1.2 已經內建 PCRE 支援,所以使用 homebrew 安裝 pdfgrep,只需要輸入 brew install pdfgrep,不需要額外再帶 --with-pcrec 選項。 (2022/4/29 補充)


問題狀況:
在 Mac 作業系統,搜尋 foo.pdf 內包含 term_a 或 term_b 的關鍵字的段落文字
pdfgrep -n --max-count 10 -i -P '(term_a|term_b)' foo.pdf
顯示錯誤訊息 pdfgrep: PCRE support disabled at compile time!

解決方式:
(如果已經安裝 pdfgrep,需要重新安裝)
brew reinstall pdfgrep --with-pcre 
(如果新安裝 pdfgrep)
brew install pdfgrep --with-pcre 

參考資料:

  1.  [pdfgrep-users] PCRE support
  2. macos - pdfgrep: how to install pdfgrep on Mac - Stack Overflow
  3. Git not built with libpcre by default · Issue #6308 · Homebrew/homebrew-core · GitHub
相關資料:
  1. Search the full text in PDF files
  2. Regular expression
  3. 鳥哥的 Linux 私房菜 -- 第十一章、正規表示法與文件格式化處理
圖片素材:

留言