1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Lua 利用 match 和正则表达式去除字符串首尾空格

Lua 利用 match 和正则表达式去除字符串首尾空格

时间:2020-07-11 04:00:03

相关推荐

Lua 利用 match 和正则表达式去除字符串首尾空格

正则表达式中,字符含义这篇文章写的不错,/meamin9/p/4502461.html。

其中^&分别代表字符串首尾,%s代表空白符[ \r \n \t \v \f ]

去除首尾空格方式为str = str:match("^[%s]*(.-)[%s]*$")或者str = str:match("^%s*(.-)%s*$"),如下所示:

str = " abc "print(str .. "def")-- " abc def"str = str:match("^[%s]*(.-)[%s]*$")print(str .. "def")-- "abcdef"

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。