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

区别Lua模式匹配中 %a+ 与 .-

时间:2016-10-08 16:47:18      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

匹配单词与匹配字符

> print(string.gsub("hello!zzy","%a+","tina"))
tina!tina       2
> print(string.gsub("hello!zzy",".-","tina"))
tinahtinaetinaltinaltinaotina!tinaztinaztinaytina       10

%a :匹配字母

.  :匹配任意字符

> print(string.gsub("zzy!jd","%a","~"))
~~~!~~  5
> print(string.gsub("zzy!jd","%A","~"))
zzy~jd  1
> print(string.gsub("zzy!jd",".","~"))
~~~~~~  6
> print(string.gsub("zzy!jd",".-","~"))
~z~z~y~!~j~d~   7

 字符短匹配与长匹配:

> test="/*tina*/;/*zz*/"
> print(string.gsub(test,"/%*.*%*/","new"))
new     1
> print(string.gsub(test,"/%*.-%*/","new"))
new;new 2

 

区别Lua模式匹配中 %a+ 与 .-

标签:

原文地址:http://www.cnblogs.com/zzy-frisrtblog/p/5938956.html

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