"%w" and "%W" difference in lua?

65 views Asked by At

%w and %W as in here: Str = string.gsub(Str, “%f[%w]cat%f[%W]”

What's the difference between a small %w and a big %W ?

Here are more examples: for _ in string.gmatch(“\n” .. Str .. “\n”, “%Wcat%W”) do ,

if Pos1 == 0 or string.find(Str, “^%W”, Pos1) then

I know %w matches a word character

So i expect %W matches a capital word character?

1

There are 1 answers

0
Oka On

%W is the complement of %w, meaning it matches all non-alphanumeric characters.

From §6.4.1 – Patterns (Lua 5.4):

%w: represents all alphanumeric characters.

For all classes represented by single letters (%a, %c, etc.), the corresponding uppercase letter represents the complement of the class. For instance, %S represents all non-space characters.