渲染zh-Hant

正規表示式

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Compile 文字 patterns to regex via ↦ regex.

Syntax: <文字> ↦ 正規表示式

Category#

literal

Examples#

radix/corpus/literalia/regex.fab (canonical · conversio)#

Compile 文字 patterns to regex via ↦ regex.

# =============================================================================
# 正規表示式 — Compile 文字 patterns to 正規表示式 via ↦ 正規表示式.
# =============================================================================
#
# What this teaches:
#   • converting 文字 strings to compiled 正規表示式 with `↦ 正規表示式`
#   • inline 正規表示式 flags like `(?i)` for case-insensitive matching
#   • combining `§` template application with 正規表示式 變換 for dynamic patterns
#
# Common mistakes:
#   • Forgetting that ↦ 正規表示式 requires a 文字 or ascii source — 整數 and other types must convert to 文字 first.
#
# See also: 讀取, 轉換, 格式文字
# =============================================================================

# literalia/regex — 文字 ↦ 正規表示式 轉換
#
# GRAMMAR:
#   轉換 :← stringLit '↦' '正規表示式'
#   templateExpr :← stringLit '(' exprList ')'   -- then ↦ 正規表示式 on the 文字 result
#
# EXPECTED OUTPUT:
#   Regex pattern diagnostics for literals, inline flags, and a template-built path.
#
# BACKEND:
#   Cross-ref 讀取/lege.fab for 正規表示式 beside stdin reads.
#   Cross-ref 格式文字/scriptum.fab for § template application.

main {
    const 正規表示式 digits ← "\d+" ↦ 正規表示式
    print digits
    const 正規表示式 word ← "(?i)\w+" ↦ 正規表示式
    print word

    # Template application → 文字, then 轉換 to 正規表示式 (dynamic path segments)
    const string tenant ← "acme"
    const 正規表示式 homePath ← "/home/§/.*"(tenant) ↦ 正規表示式
    print homePath
}

Expected output:

\d+
(?i)\w+
/home/acme/.*