Regex

Methods
4
Fields
None

Methods

MethodReturnsDescription
matches(string, string)booleanWhether regex (Pattern's syntax) matches the whole of s, as Pattern.matches(regex, s); string.match takes a Lua pattern and is no…
split(string, string){string}(string, string) -> {string}: s split around matches of regex (Pattern's syntax, so "." and "|" are regex operators), trailing…
split(string, string, number){string}
replaceAll(string, string, string)stringRegex.replaceAll: every match of regex replaced by replacement, in Matcher's replacement syntax ($1, ${name}, \\$ for a dolla…
replaceFirst(string, string, string)stringRegex.replaceFirst: the first match of regex replaced, as replaceAll replaces each.

Method details

matches

matches: (string, string) -> boolean

Whether regex (Pattern's syntax) matches the whole of s, as Pattern.matches(regex, s); string.match takes a Lua pattern and is not anchored.

split

split: ((string, string) -> {string}) & ((string, string, number) -> {string})

(string, string) -> {string}: s split around matches of regex (Pattern's syntax, so "." and "|" are regex operators), trailing empty strings removed, as a 1-based array. string.split differs: a plain separator, and it keeps trailing empty strings.

(string, string, number) -> {string}: As split(s, regex), with at most limit pieces when limit is positive (the last holds the rest), every piece when negative, trailing empty strings removed when 0.

replaceAll

replaceAll: (string, string, string) -> string

Regex.replaceAll: every match of regex replaced by replacement, in Matcher's replacement syntax ($1, ${name}, \\$ for a dollar sign), not string.gsub's (%1). A bad group reference raises.

replaceFirst

replaceFirst: (string, string, string) -> string

Regex.replaceFirst: the first match of regex replaced, as replaceAll replaces each.