Lua 正则表达式字符串切割

  一、包含空字符串

1 function split(str, sep)
2    local res = {}
3    string.gsub(str, '[^' .. sep .. ']*', function(w)
4       table.insert(res, w)
5    end)
6    return res
7 end


二、过滤空字符串
1 function split(str, sep)
2    local res = {}
3    string.gsub(str, '[^' .. sep .. ']+', function(w)
4       table.insert(res, w)
5    end)
6    return res
7 end

猜你喜欢

转载自www.cnblogs.com/mrlo/p/12341905.html
今日推荐