匹配单词与匹配字符
> 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","~"))
~~~!~~
> print(string.gsub("zzy!jd","%A","~"))
zzy~jd
> print(string.gsub("zzy!jd",".","~"))
~~~~~~
> print(string.gsub("zzy!jd",".-","~"))
~z~z~y~!~j~d~
字符短匹配与长匹配:
> test="/*tina*/;/*zz*/"
> print(string.gsub(test,"/%*.*%*/","new"))
new
> print(string.gsub(test,"/%*.-%*/","new"))
new;new