regex
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Compile string patterns to regex via ↦ regex.
Syntax: <string> ↦ regex
Category#
literal
Related#
Examples#
radix/corpus/literalia/regex.fab (canonical · conversio)#
Compile string patterns to regex via ↦ regex.
# =============================================================================
# regex — Compile string patterns to regex via ↦ regex.
# =============================================================================
#
# What this teaches:
# • converting string strings to compiled regex with `↦ regex`
# • inline regex flags like `(?i)` for case-insensitive matching
# • combining `§` template application with regex conversion for dynamic patterns
#
# Common mistakes:
# • Forgetting that ↦ regex requires a string or ascii source — int and other types must convert to string first.
#
# See also: read, conversion, format
# =============================================================================
# literalia/regex — string ↦ regex conversion
#
# GRAMMAR:
# conversion :← stringLit '↦' 'regex'
# templateExpr :← stringLit '(' exprList ')' -- then ↦ regex on the string result
#
# EXPECTED OUTPUT:
# Regex pattern diagnostics for literals, inline flags, and a template-built path.
#
# BACKEND:
# Cross-ref read/lege.fab for regex beside stdin reads.
# Cross-ref format/scriptum.fab for § template application.
main {
const regex digits ← "\d+" ↦ regex
print digits
const regex word ← "(?i)\w+" ↦ regex
print word
# Template application → string, then conversion to regex (dynamic path segments)
const string tenant ← "acme"
const regex homePath ← "/home/§/.*"(tenant) ↦ regex
print homePath
}Expected output:
\d+
(?i)\w+
/home/acme/.*