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

发布于 2024-07-06 21:39:26 字数 134 浏览 9 评论 0原文

有没有一种有效的方法可以将编译后的正则表达式(通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对风讲故事 2024-07-13 21:39:27

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

无论如何,确实转储结构可能是一个解决方案,至少你可以尝试...
[编辑] 我刚刚查看了我拥有的源代码(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文