在lua中利用正则表达式分割字符串

function string.split(s, p)
    if s == nil then
        return nil;
    end
    if p == nil then
        return s;
    end
    local rt= {};
    s = tostring(s);
    string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end );
    return rt;
end

猜你喜欢

转载自blog.csdn.net/wnagleiming/article/details/79891417
今日推荐