Garry's Mod Wiki

string.match

vararg string.match( string string, string pattern, number startPosition = 1 )

Description

Finds a Pattern in a string.

Arguments

1 string string
String which should be searched in for matches.
2 string pattern
The pattern that defines what should be matched.
3 number startPosition = 1
The start index to start the matching from, can be negative to start the match from a position relative to the end.

Returns

1 vararg
Matched text(s)

Example

local toMatch = "this is a sample text" print( string.match( toMatch, "sample" ) ) -- regex works print( string.match( toMatch, "^[a-z]" ) ) print( string.match( toMatch, "^this" ) ) print( string.match( toMatch, "^..is" ) ) print( string.match( toMatch, "text$" ) ) -- entire string print( string.match( toMatch, "^.*$" ) ) -- nil print( string.match( toMatch, "this$" ) ) print( string.match( toMatch, "nil" ) )
Output:
sample t this this text this is a sample text nil nil

Page Links


Special Pages


Wikis

?

Render Time: 97ms

DB GetPage 52
Generate Html 20
SaveChanges (1) 10
Render Body 0
Render Sidebar 12