lua-users home
lua-l archive

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

On Sun, Oct 22, 2017 at 8:40 PM Sean Conner <> wrote:
It was thus said that the Great once stated:
> hi all! :)
> 2017-10-22 1:21 GMT+02:00 Charles Heywood <>:
> >> Lua’s standard library includes regular expressions library
> >
> > I think it's a good idea to mention LPeg possibly becoming a part of the
> > language, but Lua itself doesn't have regex - it has Lua patterns.
> can you tell me more about this one?

  I think it was first brought up in 2014 on this list:

but I seem to recall it coming up a few times, with even Roberto mentioning
it could be possible to include with Lua, or have it replace the current Lua

  I use LPeg a lot, but I don't have a strong opinion on including it with
the stock Lua distribution.  It would be nice, but I know where to find it.
It would likely remain its own module (much like io or os is in the current
Lua distribution).


While I have no objection to including LPeg with the standard Lua distribution, I would strongly object to having it replace the current patterns. The beauty of the current patterns is their simplicity and easy learning curve. I find neither to be true about LPeg. I've tried to use LPeg a few times, and I find it to be confusing and not at all intuitive. In part, the use of single letters for function names leaves me scratching my head, and I can never remember what operators mean what. LPeg is powerful, yes, so I can see how it is useful. But if added to the stock Lua distribution, it should be its own standard library module (preferably with longer and more descriptive function names), without replacing patterns.

Also, unless I misunderstood something or something has changed since I last looked at it, LPeg cannot do anything requiring backtracking, so there are things matchable by patterns but unmatchable by LPeg. Possible example being "capture the three characters between a question mark and a dollar sign, immediately before the dollar sign", for which the (untested) pattern "%?.-([^$][^$][^$])%$" should match easily, but AFAICT, there is no equivalent LPeg pattern since the only way is to match up to the $ and then back up three characters.

If I am misunderstanding something, I invite somebody to correct and educate me.