在 C/C++ 中存储 PCRE 编译的正则表达式
有没有一种有效的方法可以将编译后的正则表达式(通过 regcomp()、PCRE 编译)存储在二进制文件中,以便稍后我可以从文件中读取并调用 regexec()?
或者只是将编译后的 regex_t 结构转储到文件并在需要时读回它们?
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()?
Or is it just a matter of dumping the compiled regex_t structs to the file and reading them back when needed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非你有一个超级复杂的正则表达式,我几乎看不到序列化编译的正则表达式的优势,编译时间不应该那么长。 除非您使用的是超紧嵌入系统?
无论如何,确实转储结构可能是一个解决方案,至少你可以尝试...
[编辑] 我刚刚查看了我拥有的源代码(6.7),正如我担心的那样,它并不那么简单,该结构以 void * 开头...您无法序列化指针,它们必须重新计算。
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.