Lua 字符串 匹配模式 总结

字符类

%a   --字母alpha
%d   --数字double
%l  --小写字母lower
%u  --大写字母upper
%w --字母和数字word
%x -- 十六进制
%z --代表0 zero
%s --空白符 space
%p --标点% 转义

修饰符

+ 一次或多次
*  / -  0次或多次

例子

i,j =
test = "int x;/* x */ int y;/* y */"
s1 = string.gsub(test,"/%*.-%*/","<COMMENT>")  --最短匹配 "int x;<COMMENT> int y;<COMMENT>
s2 = string.gsub(test,"/%*.*%*/","<COMMENT>") --最长匹配 int x;<COMMENT>
test2 = "<a> Hello World  <a>"
s3 = string.gsub(test2,"%b<>","")   -- Hello World 
上一篇:在线程中进行读取并写入文件和wenjia


下一篇:Mysql系列三:Centos6下安装Mysql和Mysql主从复制的搭建