Regular Expressions

Regular expressions are part of the language. The string type has methods that takes regular expressions, for example match(), split() and replace().

An example

func main():
    # Match.
    mo = "I am 6 years old.".match(re"(\d+) years")
    print("mo:         ", mo)

    # Split.
    print("split():    ", "I have 15 apples and 3 bananas.".split(re"\d+"))

    # Case-insensitive replace.
    print("replace():  ", "I want more AppLEs.".replace(re"apples"i, "bananas"))
 mys run
 Reading package configuration (0 seconds)
 Building (0.01 seconds)
mo:          RegexMatch(span=(5, 12), match="6 years") 6
split():     ["I have ", " apples and ", " bananas."]
replace():   I want more bananas.