码迷,mamicode.com
首页 > 其他好文 > 详细

Lua 字符串 匹配模式 总结

时间:2016-03-08 00:28:20      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

字符类

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

修饰符

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

 例子

i,j = string.find("the number is 1298 ","%d+" )   --15 18
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 

 

Lua 字符串 匹配模式 总结

标签:

原文地址:http://www.cnblogs.com/HuuBlog/p/5251612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!