Lightweight regex parser

坚强是说给别人听的谎言 提交于 2019-12-03 06:29:33

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!