【1】应用示例

文件类型为wav格式

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
 1 -- 判断文件类型
 2 local function isType(filename) 
 3     local res = string.match(filename, ".%.wav$")
 4     if not res then
 5         return 'is no.'
 6     else
 7         return 'is ok.'
 8     end
 9 end
10 
11 -- test
12 print(isType('123.wav'))   -- is ok.
13 print(isType('456wav'))    -- is no.
14 print(isType('wav'))       -- is no.
15 print(isType('.wav.xml'))  -- is no.
16 print(isType('test.wav'))  -- is ok.
17 print(isType('.wav.wav'))  -- is ok.

如上,判断文件类型。

【2】总结

Lua 模式匹配

 

Good Good Study, Day Day Up.

顺序  选择  循环 总结

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄