API Reference › Regex › Regex.compile
method

Regex.compile

Regex.compile(pattern) -> Regex

Compiles pattern to a reusable Regex and returns it, or null if the pattern is malformed — so a bad pattern is a value you can check, never a crash. Compiling once and reusing with Regex.test / Regex.exec avoids re-parsing the pattern every call, which matters in a hot loop.

Parameters

patternthe regular expression source

Example

program Demo {
  entry {
    let re = Regex.compile("^\\d{4}-\\d{2}-\\d{2}$")
    if Regex.test("2026-08-31", re) { print(1) }
  }
}
← All symbols