HomeIndex

Regular Expressions

It is beyond the scope of this document to describe regular expressions. Additional information can be found at Regex Primer. Dinky regular expressions do not support character classes like \w, \d\, etc.
regexcompile
Compiles a regular expression for future use
regexmatch
Returns the number of matches found.
If no match were made, null is returned, otherwise true.
local re = regexcompile("([0-9]+)") if (regexmatch("abc123xyz")) { print("found") }
regexcapture
Captures matches in a previously compiled regex
Returns an array with all the matches or null if no matches are made.
local re = regexcompile("point\\(([0-9]+),[ \\t]*([0-9]+)\\)") local a = regexcapture("point(100,200)") if (a) { print(a[1]+","+a[2]) }
regexcaptureall
Capture all the matches in a string to an array
local re = regexcompile("([0-9]+)") local a = regexcaptureall("123,456,789") if (a) { foreach(num in a) { print(num) } }
regexfree
Release a previously compiled regex
Compiled Regex expressions are not garbage collected, so it is up to the programmer to release them when done. They take up very little space and if they are reused often it's acceptable to compile them at boot and never release them.
local re = regexcompile("([0-9]+)") ... re = regexfree(re)
By storing the null return from regexrelease it lower the risk that it will be used again after releasing.