0
焦点头条

LUA正则表达式不完全指南

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




string.match(s,pattern[,init])
匹配第一个符合条件的项目
s代表目标字符串
pattern代表你要匹配的规则,见上面正则表格
init代表开始匹配的位置,默认为1,可以是负数,可不填

s = "1number123xyz"
x = string.match(s,"%d+",1) --匹配数字,一次或多次匹配,从第一号位开始找
-->x = 1     --返回值是1
x = string.match(s,"%d+",2) --匹配数字,一次或多次匹配,从第二号位开始找
-->x = 123    --返回值是123
x = string.match(s,"%d+",-4) --匹配数字,一次或多次匹配,从右起第四号位开始向右找
-->x = 3
x = string.match(s,"%d+",-3) --匹配数字,一次或多次匹配,从右起第四号位开始向右找
-->x = nil
x = string.match(s,"%d*",-3) --匹配数字,零次或多次匹配,从右起第四号位开始向右找
--> 完成匹配,返回空白




收藏 分享 邀请

发表评论

查看全部评论(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"
获取第一手剑三资讯

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