Skip to content

stdlib/regexView source ↗

regex

53 items · generated by scribe fromstdlib/regex.fd· synced 2026-11-15

stdlib/regex53 items

Contents

regex_matches

Check if a string matches a simple wildcard pattern. Supports: ? (single char), * (zero or more chars)

Example: assert(regex_matches(“report.txt”, “*.txt”)); assert(regex_matches(“cat”, “c?t”)); assert(!regex_matches(“cart”, “c?t”));

pub fn regex_matches(s: str, pattern: str) -> bool {

Parameters:

  • s: str
  • pattern: str

Returns: bool

Defined at line 28


Regex

A compiled regex: token Vec + class bitmaps + program ranges + ok flag.

pub struct Regex {

Fields:

NameType
toksVec<i64>
clsVec<i64>
progsVec<i64>
okbool

Defined at line 50


regex_compile

Compile re into a Regex (its ok flag is false on a syntax error). The regex_* functions below compile their pattern themselves.

pub fn regex_compile(re: str) -> Regex {

Parameters:

  • re: str

Returns: Regex

Defined at line 581


regex_match

True when s fully matches re (anchors implied at both ends).

Example: assert(regex_match(“hello123”, “h[ae]l+o[0-9]+”)); assert(!regex_match(“hello123!”, “h[ae]l+o[0-9]+”)); assert(regex_match(“2024-01-31”, “\d{4}-\d{2}-\d{2}”)); assert(regex_match(“cat”, “cat|dog”));

pub fn regex_match(s: str, re: str) -> bool {

Parameters:

  • s: str
  • re: str

Returns: bool

Defined at line 752


True when re matches anywhere inside s.

Example: assert(regex_search(“error: disk full”, “disk|cpu”)); assert(!regex_search(“all good”, “^error”));

pub fn regex_search(s: str, re: str) -> bool {

Parameters:

  • s: str
  • re: str

Returns: bool

Defined at line 773


regex_find_re

First position where re matches inside s, or -1.

Example: assert_eq(regex_find_re(“abc123def”, “[0-9]+”), 3); assert_eq(regex_find_re(“abc”, “[0-9]”), -1);

pub fn regex_find_re(s: str, re: str) -> i64 {

Parameters:

  • s: str
  • re: str

Returns: i64

Defined at line 782


regex_find_span

First match position and end, packed [start, end] in a Vec; [-1,-1] if none.

Example: var sp = regex_find_span(“id: 4521;”, “\d+”); assert_eq(sp.get(0), 4); assert_eq(sp.get(1), 8);

pub fn regex_find_span(s: str, re: str) -> Vec<i64> {

Parameters:

  • s: str
  • re: str

Returns: Vec<i64>

Defined at line 796


regex_replace

Replace every match of re in s with rep (literal text).

Example: var r = regex_replace(“a1b22c”, “[0-9]+”, ”#”); println(r); assert_eq(r, “a#b#c”);

pub fn regex_replace(s: str, re: str, rep: str) -> str {

Parameters:

  • s: str
  • re: str
  • rep: str

Returns: str

Defined at line 813


regex_split

Split s at every match of re; returns pieces (not the separators).

Example: var parts = regex_split(“a, b,,c”, ”,\s*”); assert_eq(parts.len(), 4); assert_eq(parts.get(1), “b”); assert_eq(parts.get(2), "");

pub fn regex_split(s: str, re: str) -> Vec<str> {

Parameters:

  • s: str
  • re: str

Returns: Vec<str>

Defined at line 850


regex_find

Find the first occurrence of a literal substring in a string. Returns the starting index, or -1 if not found.

Example: assert_eq(regex_find(“hello world”, “o w”), 4);

pub fn regex_find(s: str, sub: str) -> i64 {

Parameters:

  • s: str
  • sub: str

Returns: i64

Defined at line 884


regex_contains

Check if a string contains a substring.

Example: assert(regex_contains(“hello”, “ell”));

pub fn regex_contains(s: str, sub: str) -> bool {

Parameters:

  • s: str
  • sub: str

Returns: bool

Defined at line 892


regex_starts_with

Check if a string starts with a prefix.

Example: assert(regex_starts_with(“hello”, “he”));

pub fn regex_starts_with(s: str, prefix: str) -> bool {

Parameters:

  • s: str
  • prefix: str

Returns: bool

Defined at line 900


regex_ends_with

Check if a string ends with a suffix.

Example: assert(regex_ends_with(“hello”, “lo”));

pub fn regex_ends_with(s: str, suffix: str) -> bool {

Parameters:

  • s: str
  • suffix: str

Returns: bool

Defined at line 908


regex_len

Get the length of a string.

Example: assert_eq(regex_len(“hello”), 5);

pub fn regex_len(s: str) -> i64 {

Parameters:

  • s: str

Returns: i64

Defined at line 916


Generated by scribe, the Fides documentation generator