[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Emulating advanced regex features using Lua patterns and pure Lua code
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Mon, 20 Jun 2011 14:44:59 +0200
On 20/06/2011 13.13, steve donovan wrote:
On Mon, Jun 20, 2011 at 12:12 PM, Lorenzo Donati
if pcre.match( haystack, "^foo|bar$" ) then ...
may be rewritten in pure Lua as:
if haystack:match "^foo$" or haystack:match "^bar$" then ...
Ah, but soon as you get multiple alternation, especially nested, then
the resulting code is not so obvious. And obviously it is going to be
slower than any regexp implementation. OK, that may be acceptable for
the application, but the code generation could get hairy fast.
I had that feeling, unfortunately :-(
Another idea is to use LPeg to implement a regexp subset - that should
be fast. But it does require non-triivial knowledge of LPeg which I
understand is not on your immediate to-do list ;)