开发者

lua gsub %b <-- how does this work?

开发者 https://www.devze.com 2022-12-29 04:52 出处:网络
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))

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

精彩评论

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