function trim(s)
return (string.gsub(s,"^%s*(.-)%s*$","%1"));
end
a=" <string>8.1</string>"
print(a);
--正则方法:
_,_,d=string.find(trim(a),"<string>(.+)</string>");
print(d);
--截取方法:
b=string.find(a,">",1,false);
c=string.find(a,"</",1,false);
print(string.sub(a,b+1,c-1));
--替换方法:
a=string.gsub(trim(a),"<string>","")
a=string.gsub(trim(a),"</string>","")
print(a);
LUA 捕获、正则、截取、替换
最新推荐文章于 2024-06-20 16:26:00 发布