0

I want to use libpcre2 to match substrings in plain text files, but libpcre2 does not provide: pcre2_match_file() or pcre2_match_fd() API. It seems that I need to open the file myself and take each line and pass it to the pcre2_match() function in turn?

I am not sure if I should do this.

Is there a higher performance way besides this? For example using mmap() to map files to memory?

I only tried matching a buffer and wanted to expand to match an entire plain text file.

#include <pcre2.h>

int pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext);
  • You have to provide the strings to search in. Doesn't have to be line at a time if something else makes sense. `mmap()` is nice for searching the entire file in one go, yes. – Shawn May 28 '19 at 17:03
  • thank you for your answer Shawn. If I want to get the offset of the substring in each line, does it mean that I should pass the file contents line by line to pcre2? – chenzhongxiang Jul 02 '19 at 15:11

0 Answers0