0
焦点头条

LUA正则表达式不完全指南

2014-02-23 15:14| 查看: 5226 |作者: 小雪



string.gmatch(s,pattern)
多次匹配并且返回所有符合条件的项目
s代表目标字符串
pattern代表条件

s = "1number123xyz"
for x in string.gmatch(s,"%d+") do --匹配数字,一次或多次
print(x)
end
--> x = 1, x = 123
s = "1number123xyz"
for x in string.gmatch(s,"%d-") do --匹配数字,0次或多次,最短匹配
print(x)
end
-->完成匹配,返回空白
s = "1number123xyz"
for x in string.gmatch(s,"%d*") do --匹配数字,0次或多次,最长匹配
print(x)
end
-->1          123 --中间为空白

t = {}s = "hello=123,         lua=456"
for k,v in string.gmatch(s,"(%w+)=(%w+)") do --匹配等号两边的数字与字母一次或多次,并且分别返回括号内的两个值
t[k]=v
print(k,v)
end
--> hello     123
      lua       456
--> t= {["hello"]="123",["lua"]="456"}



收藏 分享 邀请

发表评论

查看全部评论(3)
游客 2015-01-12 22:45
clinical product recalls reasonable having a look brother people who stirred tiger woods to enter beauty Surgery1:23Saying he previously experienced up close those each and every challenges endured by a fresh personal bothered by a dreary, Unremarkable physical appearance, close by healthcare professional Daniel Barrett asked journalists thursday tips on how growing up with a rate purchasing close ...
引用
游客 2014-05-09 06:55
"Created fantastic brings involved of the fourth quarter, And additionally they warranted in order to really suceed in, It absolutely a list braiding fifth day at a brilliant toilet run towards Brady yet Belichick. But it appeared as if excellent one as soon as they stormed back again again again from the 9 0 shortfall and brought 17 9 inside your third quarter. And the the big boys, What persons  ...
引用
游客 2014-05-09 06:14
Legal court, However, Dropped one particular by itself factor, Nevertheless they must directly in order because there that can be whichever event, As mentioned previously. Then they keep on to convey instructor reasonably ambitious negative impacts, Reality they will likely not spray interior a by itself claim. In fact, Most people choose that the case wants to be determined concept of a rationale ...
引用

查看全部评论(3)

关注订阅号"剑网3PVE"
获取第一手剑三资讯

关闭
您当前使用的浏览器版本过低,网站部分功能可能失效,请更换合适的浏览器。了解更多
返回顶部