lua-users home
lua-l archive

Re: Patterns: Why are anchors not character classes?

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


2015年07月14日 18:21 GMT+02:00 John Hind <john.hind@zen.co.uk>:
> I've just had another bout of wrestling with patterns, probably the most
> obscurantist part of Lua and the only bit I've never been able to learn and
> always have to get "Programming in Lua" off the shelf.
Oh, I just use the online manual and pick the last string function in
the index. The patterns come immediately after. I can't remember
all of them either. :-)
> Take the simple case of parsing a comma-separated list
That's [^,]+ or [^,]* depending on whether empties are allowed.
> If the start and end anchors behaved like character classes we could do
> better. For regularity they probably should be %^ and %$
An interesting notion. I'll probably use it.
> The other thing I'd like to see is some "standard" patterns as constants in
> the string library for the common functions that a C programmer for example
> will miss ("trimright", "trimleft" and "trim", for example).
Well, now. A little module that monkeypatches those into the string library
is surely not too hard?

AltStyle によって変換されたページ (->オリジナル) /