lua gsub %b <-- how does this work?
In the following lua co开发者_运维知识库de:
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}" ?
%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 }
.
精彩评论