string.match
From GMod Wiki
Function | |
Syntax |
string.match( String string, String pattern[, Integer startindex ] ) Where is this used? |
Description: | |
If it finds a match in the pattern, it returns that. Otherwise, it will return nil . | |
Returns: | String [,String , String , ...] |
Part of Library: | String |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=String.match]String.match [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Examples
Description | Shows the use of multiple captures. |
---|---|
Used on | |
Code | local a = "one: two" local one,two = string.match(a, "(%l*): (%l*)") print("One: " .. one .. ", two: " .. two); |
Output | One: one, two: two |
Additional Notes
- This is like string.find, but it returns the matched string instead of an Integer .
- Allows the usage of Regular Expressions.
- If () captures are used, it will return each of the captures as a separate value