lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 20/06/2011 14.13, David Kastrup wrote:
steve donovan<>  writes:

On Mon, Jun 20, 2011 at 12:12 PM, Lorenzo Donati
<>  wrote:
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.

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 ;)


I know that, but: 1) it has LPeg as external dependency and 2) even if that dependency is acceptable, it has an unusual syntax, which (IIRC) moreover doesn't completely abstract over the underlying LPeg features, so you need to understand LPeg to a certain extent to use re's more advanced features.