lua-users home
lua-l archive

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


It was thus said that the Great Soni L. once stated:
> On 18/07/15 10:38 PM, Sean Conner wrote:
> >It was thus said that the Great Soni L. once stated:
> > >
> > >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!)
> > 
> >   It can't do that now because 'a' to '%' isn't a range.  '%' is 37, 'a' 
> >   is 97, so of course:
> >
> >		x = '%'
> >		print(x:match"[a-%%]"))
> >
> >fails.  But if you do:
> >
> >		x = '%'
> >		print(x:match"[%%-a]"))
> >
> >it works.
> 
> Actually the manual says it's undefined.

  The actual text is:

	The interaction between ranges and classes is not defined. 
	Therefore, patterns like [%a-z] or [a-%%] have no meaning.

But!  There is this:

	%x: (where x is any non-alphanumeric character) represents the
	character x.  This is the standard way to escape the magic
	characters. Any non-alphanumeric character (including all
	punctuations, even the non-magical) can be preceded by a '%' when
	used to represent itself in a pattern.

So to me, that says that '%%' is NOT a class and can therefore be used as
mentioned.  I wonder what Roberto meant by the example of "[a-%%]".  Perhaps
a typo?

  -spc