lua-users home
lua-l archive

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


Hi:


On Wed, Mar 5, 2014 at 2:15 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
>     > =select( 2, string.gsub( "AAA", "^A", "%0" ) )
>     1
>     > =select( 2, string.gsub( "AAA", "A", "%0" ) )
>     3
Ok, conceded, your lua-fu is strong and it can aparently be done by
overusing a mutative operation. Now you've demonstrated me that I
cannot reduce gsub to succesive finds. Thanks.

> Allowing to anchor a pattern at a user-specified position seems more useful
> than "always fail". "Always fail" is trivial to implement, too. Just
> translate your sentence above into a Lua one-liner and you are done.

I'm not discussing which is more useful, more on what is least
surprissing. After more than 25 years of working with regular
expressions this is the first time I've seen this behaviour. If you
resort to mutative operations, anchoring is trivial, just find on
substring. Using the customary character for start of string, telling
it matches on start of subject string without defining subject string
and then making it mach on start of explored region is my problem. I
wouldn't care of lua's behaviour if the manual defined subject string.
I would care a little less if it used a distinct charset than regular
expressions, although I would consider it should be defined. And the
surprise problem is not only for people like me who came to lua after
using lots of regexes, it will hit people who start in lua and go to
another languages too.

And your sugestion for the "quoty text" is I substitute all my find
code with a return nil ? It seems so. Are you suggesting I put a
return nil, or that I sanitize every pattern I use to see wether it
starts with ^ or what?

Francisco Olarte.