轻量级正则表达式解析器

发布于 2024-07-09 02:29:44 字数 151 浏览 4 评论 0 原文

我想使用正则表达式解析器来帮助 C 应用程序中的一些字符串处理。 我理想地寻找轻量级和开源的东西。 目标平台是嵌入式系统,因此我们希望尽可能节省内存消耗。 我在网上找到了许多选项,但想知道是否有人可以提出可能在这种特定情况下有所帮助的其他建议。

非常感谢,

I'd like to use a Regex parser to aid in some string processing in a C application. I'm ideally looking for something lightweight and open-source. The target platform is an embedded system so we're looking to save as much as possible with memory consumption in particular. I've found a number of options online but was wondering if anyone can make additional suggestions that may help in this particular context.

Many thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

你不是我要的菜∠ 2024-07-16 02:29:44

Scintilla 是一个开源文本编辑器组件,使用 Ozan S. Yigit 的 RE 引擎

选择它是因为它位于公共领域(因此没有阻碍许可证)并且非常轻量级。 但它有点有限......对于它的价值,RESearch.cxx 使用稍微更现代的代码(转换为 C++,但将其转换回 C 应该不会很复杂),并进行了一些小的扩展我自己(支持 \d \s \w 等)。

还有一些替代方案,例如 Henry Spencer 的正则表达式库

想想看, Lua 正则表达式引擎(在字符串库中,gsub实现等)可能也很快而且很小,就像语言本身一样。 它有其怪癖和局限性,但非常有用。

业余项目 LPeg< /a> 可以是 RE 的一个有趣的替代品,仍然轻量级但功能强大。

Scintilla, an open source text editor component, uses Ozan S. Yigit's RE engine

It was chosen because it is in the public domain (so no encumbering license) and very lightweight. But it is a bit limited... For what it is worth, RESearch.cxx uses a slightly more modern code (converted to C++ but it shouldn't be complex to convert it back to C) with some minor extensions made by myself (support of \d \s \w etc.).

There are some alternatives, like Henry Spencer's regular expression libraries.

Come to think of it, the Lua regex engine (in string library, gsub implementation among others) is probably fast and small too, like the language itself. It has its quirks and limitations, but it is very usable.

The side project LPeg can be an interesting alternative to REs, still lightweight yet powerful.

兮颜 2024-07-16 02:29:44

如果您不需要全功能的正则表达式实现(听起来您不需要),那么由 Brian Kernighan 和 Rob Pike 编写的代码在 美丽的代码可能会满足您的需求。 我找到了 Dobb 博士的文章,我认为这是代码的起源出现在书中。

If you don't require a full featured regex implementation (and it sounds like you don't) then the code written by Brian Kernighan and Rob Pike highlighted in Beautiful Code will probably work for your needs. I found a Dr. Dobb's article which I think is the origination of the code which appears in the book.

苏佲洛 2024-07-16 02:29:44

考虑到您的轻量级要求,我建议 Henry Spencer 的正则表达式库 它实现了 POSIX BRE 和 ERE 正则表达式风格。 这些是您的用户可能已经熟悉的标准正则表达式风格。

Given your lightweight requirements, I'd recommend Henry Spencer's regex library which implements the POSIX BRE and ERE regex flavors. These are standard regex flavors that your users are likely already familiar with.

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