Garry's Mod Wiki

string.gmatch

  function string.gmatch( string data, string pattern )

Description

Using Patterns, returns an iterator which will return either one value if no capture groups are defined, or any capture group matches.

Arguments

1 string data
The string to search in
2 string pattern
The pattern to search for

Returns

1 function
The iterator function that can be used in a for-in loop

Example

Explodes the string for each space and comma in the string

str = "qwe,a cde" for s in string.gmatch(str, "[^%s,]+") do print(s) end
Output:
qwe a cde