tags:

views:

98

answers:

1

In the following lua code:

function interp(s, tab)
  return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
end

what does the %b mean?

and how does this match stuff like "${name}" ?

+4  A: 

%bXY matches a sequence of characters that starts with X and ends with Y. Thus, %b{} matches {......} for any characters in between the braces.

The overall pattern in your example code first matches a $ character followed by a {, any number of characters, and then a }.

Amber
anon
This is explained in the manual in http://www.lua.org/manual/5.1/manual.html#5.4.1 -- see "A pattern item can be..."
lhf