在C / C ++中存储PCRE编译的正则表达式

时间:2022-08-05 22:06:33

Is there an efficient way to store the compiled regexes (compiled via regcomp(), PCRE) in a binary file, so that later I can just read from the file and call regexec()?

有没有一种有效的方法来存储已编译的正则表达式(通过regcomp(),PCRE编译)在二进制文件中,以便稍后我可以从文件中读取并调用regexec()?

Or is it just a matter of dumping the compiled regex_t structs to the file and reading them back when needed?

或者只是将编译好的regex_t结构转储到文件中并在需要时将其读回?

1 个解决方案

#1


4  

Unless you have a super-complex regex, I hardly see an advantage of serializing the compiled regex, the compilation time shouldn't be that big. Unless you are on a super-tight embed system?

除非你有一个超级复杂的正则表达式,我几乎看不到序列化编译的正则表达式的优势,编译时间不应该那么大。除非你是一个超紧密的嵌入系统?

In any case, indeed dumping the structure might be a solution, at least you can try...
[EDIT] I just looked at the source I have (6.7) and as I feared, it is not so simple, the structure starts with a void *... You can't serialize pointers, they have to be recomputed.

在任何情况下,确实倾倒结构可能是一个解决方案,至少你可以尝试... [编辑]我只是看了我的源(6.7),因为我担心,它不是那么简单,结构开始于void * ...你不能序列化指针,它们必须重新计算。

#1


4  

Unless you have a super-complex regex, I hardly see an advantage of serializing the compiled regex, the compilation time shouldn't be that big. Unless you are on a super-tight embed system?

除非你有一个超级复杂的正则表达式,我几乎看不到序列化编译的正则表达式的优势,编译时间不应该那么大。除非你是一个超紧密的嵌入系统?

In any case, indeed dumping the structure might be a solution, at least you can try...
[EDIT] I just looked at the source I have (6.7) and as I feared, it is not so simple, the structure starts with a void *... You can't serialize pointers, they have to be recomputed.

在任何情况下,确实倾倒结构可能是一个解决方案,至少你可以尝试... [编辑]我只是看了我的源(6.7),因为我担心,它不是那么简单,结构开始于void * ...你不能序列化指针,它们必须重新计算。