开发者

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 }.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜