NIAOJoin Beta
Ecosystem

re

available

Regular Expressions

Core Standard Library

Overview

re wraps the Rust regex engine. Use it to pull structured data out of logs, validate input, or split strings on a pattern. Syntax matches Rust regex (not PCRE, no lookbehind).

For code that runs the same pattern thousands of times, compile it once and reuse the handle. Capture groups come back numbered or by name; flags cover case-insensitive and multiline matching with proper Unicode behavior.

  • Capture groups
  • Search & replace
  • Compiled patterns
  • Unicode-aware

Import

import
import "re"

Quick start

quick start
import "re"
let pattern = re.compile(r"(d{4})-(d{2})-(d{2})")
let m = pattern.match("Event on 2026-07-08")
print(m.group(1))

Capabilities

High-level overview of what re is for.

Capture groups

Parentheses in the pattern become numbered groups (and named groups if you use (?P<name>...)).

Search & replace

Find all matches, or replace with a fixed string. Global replace walks the whole input.

Compiled handles

compile parses the pattern once; subsequent match calls skip that cost.

Unicode-aware flags

Case-insensitive and multiline flags respect Unicode rules, not just ASCII byte ranges.

API reference

26 functions and methods in re. Grouped by category from the standard library docs.

Match object

SignatureDescription
fullMatched substring
startStart index (byte offset, inclusive)
endEnd index (byte offset, exclusive)
groupsCapture groups - index `0` is the full match, `1+` are parenthesized groups

Validation & escaping

SignatureDescription
re.valid(pattern, flags?)`true` if pattern compiles
re.escape(text)Escape literal metacharacters

Matching

SignatureDescription
re.test(pattern, text, flags?)`true` if pattern matches anywhere in `text`
re.match(pattern, text, flags?)`true` if the entire string matches
re.search(pattern, text, flags?)First match → match object, or `nil`
re.find_all(pattern, text, flags?)All matches → array of match objects
re.find_all_strings(pattern, text, flags?)All matches → array of matched strings
re.count(pattern, text, flags?)Number of non-overlapping matches

Replace & split

SignatureDescription
re.replace(pattern, text, replacement, flags?)Replace all matches
re.replace_n(pattern, text, replacement, count, flags?)Replace first `count` matches
re.split(pattern, text, flags?)Split on pattern → string array

Compiled handles

SignatureDescription
re.compile(pattern, flags?)Compile pattern → positive int handle
re.close(handle)Release handle; returns `true` if it existed
re.test_h(handle, text)Same as `re.test`
re.match_h(handle, text)Same as `re.match`
re.search_h(handle, text)Same as `re.search`
re.find_all_h(handle, text)Same as `re.find_all`
re.find_all_strings_h(handle, text)Same as `re.find_all_strings`
re.replace_h(handle, text, replacement)Same as `re.replace`
re.replace_n_h(handle, text, replacement, count)Same as `re.replace_n`
re.split_h(handle, text)Same as `re.split`
re.count_h(handle, text)Same as `re.count`

Related libraries

More from Core Standard Library.

available

json

JSON Parse & Manipulate

Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.

  • parse & stringify
  • Dot-path access
  • Deep merge
  • Pretty-print
Read more
available

io

File & Path I/O

Read and write files, stream large inputs, and work with paths. Blocking I/O can run on background threads.

  • Whole-file read/write
  • Streaming handles
  • Background I/O
  • Path helpers
Read more
available

time

Wall-Clock & Time Zones

Timestamps, formatting, parsing, and time zones. Built on chrono and chrono-tz, DST handled correctly.

  • IANA time zones
  • strftime formats
  • Datetime values
  • Date math
Read more