Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Lua pattern matching flavor

Open Gethe opened this issue 11 years ago • 18 comments
trafficstars

I would love to see support for Lua on this site. http://www.lua.org/pil/20.1.html

Gethe avatar Jul 11 '14 20:07 Gethe

Lua regex is unfortunately too different and would require a great change in existing code as it stands right now. Maybe in the future, but it is unfortunately not very likely unless I decide to do a massive rehaul. I wonder why lua went with the syntax that they did..

firasdib avatar Jul 22 '14 09:07 firasdib

It's been two years since this request and we've seen quite a bit of change to the site. Any chance that the possibility of adding support for Lua could be re-visited? :+1:

Kruithne avatar Nov 01 '16 21:11 Kruithne

That depends on what regex engine lua uses, if it can be emulated with the existing ones or have its own ported to JS. Is there a complete link to the spec sheet?

firasdib avatar Nov 01 '16 21:11 firasdib

I'm not sure if there's a full spec floating around, as the Lua documentation is very lax in general, but there's a reference here: https://www.lua.org/pil/20.2.html

Kruithne avatar Nov 01 '16 21:11 Kruithne

It looks really simple, other than those weird percents it looks quite similar to normal regex.

@firasdib You asked above why they did it, they say in the docs that it's because the POSIX implementation is too long and theirs is just quarter of that in length.

TWiStErRob avatar Nov 01 '16 22:11 TWiStErRob

We could potentially implement Lua as a shim on top of PCRE, since it looks like its a subset of PCRE anyway.

firasdib avatar Nov 21 '16 09:11 firasdib

This would be nice !

X-Raym avatar Apr 30 '18 00:04 X-Raym

I think this would be a great addition, as I often find myself backporting PCRE expressions I made on the site to Lua and banging my head on the discrepancies.

EntranceJew avatar Jun 28 '19 23:06 EntranceJew

do you have a short-list of stuff you often run in to?

Doqnach avatar Jul 02 '19 07:07 Doqnach

Any interest in restarting this discussion? I adore regex101 and Lua. I'll put $100 donation reward on this feature getting merged.

joshenders avatar Nov 15 '20 14:11 joshenders

@joshenders I think this is too much work as of right now, unfortunately. Ideally I'd like to get C# working first.

firasdib avatar Dec 22 '20 12:12 firasdib

@joshenders I think this is too much work as of right now, unfortunately. Ideally I'd like to get C# working first.

Now that the C# is done, any chance you will work on LUA? I recently started working heavily on Mediawiki and Wikibase: LUA is their scripting language of choice (via Scribunto) and it would be great to apply the power of Regex101 to it.

Thanks for your effort

lucamauri avatar Jun 02 '22 15:06 lucamauri

i'd certainly like to see this added.

speedwaystar avatar Feb 03 '23 14:02 speedwaystar

💯

dsully avatar Apr 04 '23 02:04 dsully

Lua patterns have some interesting features of their own:

  • %bxy where x and y and two distinct characters matches a sequence starts with x and ends with y so that the number of x in that sequence is equals to the number of y. This is somewhat similar to x(?:(?<c>x)|(?<-c>y)|[^xy])*(?(c)(?!))y in .NET.
  • %f[...] where [...] is a character set matches a position where the next character matches [...] and the previous doesn't. A negated set (%f[^...]) can be used to invert the order. Its regex equivalent is (?<![^...])(?=[...]|$).

However, their quirks far outweight the features: Lua is not very internationalized by design. Lua patterns match by bytes and metasequences like %a (letters) are only ASCII-aware. For example, ('Á'):match('%a') returns nil whereas ('Á'):match('%A') returns the first byte. If Lua patterns were to be added to the bunch, these will need to be fully addressed.

InSyncWithFoo avatar Sep 04 '23 10:09 InSyncWithFoo

Ten years passed, is there any update of this topic?

DeznekCZ avatar May 12 '24 19:05 DeznekCZ

I am still interested as well. This is such a wonderful tool! Thank you.

joshenders avatar May 12 '24 21:05 joshenders