lua-users home
lua-l archive

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




On 18/07/15 08:17 PM, Soni L. wrote:


On 18/07/15 07:43 PM, Rena wrote:
On Sat, Jul 18, 2015 at 3:26 PM, Tom N Harris <whoopdedo@whoopdedo.org> wrote:
On Saturday, July 18, 2015 02:45:18 PM Rena wrote:
Well, regardless of whether it's classified as a character class or a set or a special case or a fruit or a vegetable, I've many times wished I could write a pattern such as "[ ^]%w+[ $]" (match one or more word characters bounded by either a space or the start/end of a string). Though ^ already
has a meaning there...
No regex-like implementation I know of works like that, though. I'd write "(^| )%w+($| )". Lua doesn't have the alternation operator however. Is that what's really being asked for? But disguised as a discussion about character classes.

--
tom <telliamed@whoopdedo.org>

Alternation would be great, but I think it's been discussed before and
it would add too much complexity to the implementation.

Why not add the whole patterns to... everything?

[(abc)(def)] would match either "abc" or "def"; [(aaa)-(fff)] would convert a 3 letter sequence to a number and compare it against the number form of aaa and fff (it gives you more than just a-f 3 times, you can also match "a¬" (UTF-8; challenge for you: figure out why)); Guess what [a-%%] would do? It would match anything from 'a' to the '%' sign! (which you can't currently do, because %% is a character class!)

Way more powerful than Lua patterns and not that hard to write if you have access to tail calls. I'd take it over Lua patterns anytime, even if it is clunkier. We also wouldn't need "0-or-more" modifiers as you would be able to just x?<mod>!

Actually scratch that last part, it should be x<mod>?, because "?" would first try to match with 1-or-more, then if it fails it would match 0. With x?<mod> it attempts "?" indefinitely. (try match ?, it matches, try it again, it matches, even tho they're empty matches it still matches)

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.