string.gmatch
From GMod Wiki
Function | |
Syntax |
string.gmatch( String haystack, String needle, [ Function extra function ] ) Where is this used? |
Description: | |
Returns an iterator function that, each time it is called, returns the next captures from pattern over string s. If pattern specifies no captures, then the whole match is produced in each call. | |
Returns: | Function |
Part of Library: | String |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=String.gmatch]String.gmatch [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Description | Example |
---|---|
Used on | |
Code | s = "hello world from Lua" for w in string.gmatch(s, "%a+") do print(w) end |
Output | hello world from Lua |
Description | Example |
---|---|
Used on | |
Code | t = {} s = "from=world, to=Lua" for k, v in string.gmatch(s, "(%w+)=(%w+)") do t[k] = v end |
Output | N/A |
Additional notes
- An alias for this is string.gfind.