Built-in

Regex

let re = Regex.compile("(\\w+)\\s+(\\w+)")
let m = re.find("hello world")
if m is not None {
    print(m!!.group(0))         # hello world
    print(m!!.group(1))         # hello
    print(m!!.group(2))         # world
}

let digits = Regex.compile("\\d+")
let matches = digits.find_all("abc 123 def 456")
print(len(matches))             # 2
MethodReturnsDescription
Regex.compile(pattern)RegexCompile a regex
.find(input)Match?First match
.find_all(input)List[Match]All non-overlapping matches
.replace_all(input, replacement)StrReplace all matches
.replace_first(input, replacement)StrReplace first match
.group(index)Str?Capture group (0 = full match)
.groups()List[Str?]All groups