Lua gsub% b <- how does it work?

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% b mean?

and how does it look like "$ {name}"?

+2


source share


1 answer


%bXY

matches a sequence of characters that starts with X

and ends with Y

. Thus, %b{}

matches {......}

for any characters between curly braces.



The general pattern in your example code first matches a character $

, followed by {

any number of characters, and then }

.

+4


source







All Articles