Module regex

Module regex 

Source
Expand description

Regular expression operations for Seq

These functions are exported with C ABI for LLVM codegen to call. Uses Rust’s regex crate - fast, safe, no catastrophic backtracking.

§API

# Match check
"hello world" "wo.ld" regex.match?      # ( String String -- Bool )

# Find first match
"a1 b2 c3" "[a-z][0-9]" regex.find      # ( String String -- String Bool )

# Find all matches
"a1 b2 c3" "[a-z][0-9]" regex.find-all  # ( String String -- List )

# Replace first occurrence
"hello world" "world" "Seq" regex.replace
# ( String pattern replacement -- String )

# Replace all occurrences
"a1 b2 c3" "[0-9]" "X" regex.replace-all
# ( String pattern replacement -- String )

# Capture groups
"2024-01-15" "(\d+)-(\d+)-(\d+)" regex.captures
# ( String pattern -- List Bool ) returns ["2024", "01", "15"] true on match

# Split by pattern
"a1b2c3" "[0-9]" regex.split            # ( String pattern -- List )

Functions§

patch_seq_regex_captures
Extract capture groups from a pattern match
patch_seq_regex_find
Find the first match of a pattern in the string
patch_seq_regex_find_all
Find all matches of a pattern in the string
patch_seq_regex_match
Check if a pattern matches anywhere in the string
patch_seq_regex_replace
Replace the first occurrence of a pattern
patch_seq_regex_replace_all
Replace all occurrences of a pattern
patch_seq_regex_split
Split a string by a pattern
patch_seq_regex_valid
Check if a pattern is a valid regex