Lua: is [^%d%u] equal to [%D%U]?

61 views Asked by At

As in the title: in Lua programming language is [^%d%u] equal to [%D%U] in it's buildin regular expressions ?

I would say it is but I suspect that this question is asked in the book

Programming in Lua, Fourth Edition
Roberto Ierusalimschy
Copyright © 2016, 2003 Roberto Ierusalimschy

on the page 89 for a reason. But I can't think about any reason why those would be different.

1

There are 1 answers

0
Wiktor Stribiżew On

These are different patterns.

  • [^%d%u] matches any char other than digit and uppercase letters. So it matches . and _ and a, but does not match 0 and A.
  • [%D%U] matches any chars since it matches any non-digit or any non-uppercase letter.

Note that in a negated bracket expression ([^...]), the relationship between the patterns inside it is AND and in a positive bracket expression ([...]), it is OR.