类型 函数 库 string.* 返回值 字符串 修订版 发行版 2024.3703 关键字 string、match、find 另请参阅 string.gmatch() string.find()
通过匹配字符串中的模式来提取子字符串。如果找到匹配项,则返回模式中的捕获项;否则返回 nil
。如果 pattern 未指定任何捕获项,则返回整个匹配项。
string.match( s, pattern [, init] ) s:match( pattern [, init] )
String. 任何字符串。
Number. 指定从 s
中的何处开始搜索的数字。默认值为 1
;可以为负值。
print( string.match( "I have 2 questions for you.", "%d+ %a+" ) ) --> 2 questions print( string.format( "%d, %q", string.match( "I have 2 questions for you.", "(%d+) (%a+)" ) ) ) --> 2, "questions"