regex module

ECMAScript-flavored regular expressions (powered by std::regex). Use for matching, capturing, replacement, and splitting.

import "regex" as regex;

print(regex.test("\\d+", "hello 42"));           // true
print(regex.match("(\\w+)@(\\w+)", "[email protected]"));// ["[email protected]", "ada", "a"]
print(regex.replace("\\s+", "two  spaces", "_"));// "two_spaces"
print(regex.split(",\\s*", "a, b,c"));            // ["a", "b", "c"]

API

FunctionDescription
regex.test(pattern, s) → boolTrue if pattern matches anywhere in s.
regex.match(pattern, s) → list | nullFirst match as [full, group1, group2, ...], or null.
regex.match_all(pattern, s) → list of listsEvery match.
regex.replace(pattern, s, replacement) → stringReplace first match. Use \1, \2 in replacement to reference capture groups.
regex.replace_all(pattern, s, replacement) → stringReplace every match.
regex.split(pattern, s) → listSplit on each match.
regex.escape(s) → stringEscape regex metacharacters so the result matches s literally.

Notes

  • Patterns are strings — escape backslashes when needed ("\\d" for \d).
  • Bnlang has no regex literal syntax (no /foo/g). All flags are baked into the pattern (e.g. (?i) for case-insensitive).