Tutorial by Examples

Instead of using regex, the Lua string library has a special set of characters used in syntax matches. Both can be very similar, but Lua pattern matching is more limited and has a different syntax. For instance, the character sequence %a matches any letter, while its upper-case version represents al...
The find function First let's take a look at the string.find function in general: The function string.find (s, substr [, init [, plain]]) returns the start and end index of a substring if found, and nil otherwise, starting at the index init if it is provided (defaults to 1). ("Hello, I am a ...
How it works The string.gmatch function will take an input string and a pattern. This pattern describes on what to actually get back. This function will return a function which is actually an iterator. The result of this iterator will match to the pattern. type(("abc"):gmatch ".&quo...
do not confuse with the string.sub function, which returns a substring! How it works string argument ("hello world"):gsub("o", "0") --> returns "hell0 w0rld", 2 -- the 2 means that 2 substrings have been replaced (the 2 Os) ("hello worl...

Page 1 of 1