Reference · reference

regex module

2 min read · 2026-09-02 · config-weave 0.1.0

use regex matches regular expressions against strings, so a script does not have to shell out to grep or sed. config-weave registers it from wscript-std. Patterns use Rust regex syntax: no backreferences, no lookaround, and matching runs in linear time. No function returns a Result. An invalid pattern is a runtime fault that surfaces as the step's Error status, because patterns are literals in practice and a script has no way to recover from a bad one.

The pattern comes first

Every function takes (pattern, text). The two arguments have the same type, so swapping them compiles and then never matches.

is_match

rust
regex::is_match(pattern: string, s: string) -> bool

Whether the pattern matches anywhere in s.

find and find_all

rust
regex::find(pattern: string, s: string) -> Option[string]
regex::find_all(pattern: string, s: string) -> List[string]

find returns the first match, or None. find_all returns every non-overlapping match in order.

replace

rust
regex::replace(pattern: string, s: string, rep: string) -> string

Replaces every match with rep. Inside rep, $1 and $name expand to the capture groups of that match.

captures

rust
regex::captures(pattern: string, s: string) -> Option[List[string]]

Returns the capture groups of the first match, with group 0, the whole match, first. A group that did not participate is the empty string. Returns None when nothing matches.

split

rust
regex::split(pattern: string, s: string) -> List[string]

Splits s around every match.

rust
use regex

let major = match regex::captures("version ([0-9]+)[.]([0-9]+)", out.stdout) {
    Some(groups) => groups[1],
    None => "0",
}