正则表达式中,字符含义这篇文章写的不错,/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"