ludic/ns-regex.html
2026-09-17 22:10:03 +00:00

22 lines
No EOL
4.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Regex — Ludic</title>
<meta name="description" content="Regular expressions with PCRE/PECL-compatible syntax over a **linear-time** Thompson NFA (a Pike VM), so a bad pattern from a modder can never trigger…">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <span class="here">Regex</span></div>
<div class="item-head"><span class="kind-badge kind-namespace">namespace</span><h1 id="top">Regex</h1></div>
<p class="ns-blurb">Regular expressions with PCRE/PECL-compatible syntax over a **linear-time** Thompson NFA (a Pike VM), so a bad pattern from a modder can never trigger catastrophic backtracking — matching is <code>O(n·m)</code>, never exponential. Compile a pattern once and reuse it; an invalid pattern is an <a href="regex-compile"><code>error value</code></a>, never a crash. Supported: literals, <code>.</code>, classes <code>[...]</code> with ranges/negation and <code>\d \w \s</code> (and their negations), anchors <code>^ $</code>, alternation <code>|</code>, capturing and <code>(?:…)</code> groups, and the quantifiers <code>* + ?</code> and <code>{n,m}</code> in greedy or lazy form. Backreferences and look-around are out of scope for a linear engine.</p>
<div class="ns-methods"><a class="ns-method" href="regex-compile.html"><code class="nm-sig">Regex.compile(pattern) -&gt; Regex</code><span class="nm-tip">Compile a pattern once for reuse; returns an error value (null) if it is invalid.</span></a><a class="ns-method" href="regex-valid.html"><code class="nm-sig">Regex.valid(pattern) -&gt; bool</code><span class="nm-tip">True if the pattern is well-formed (compiles without error).</span></a><a class="ns-method" href="regex-matches.html"><code class="nm-sig">Regex.matches(text, pattern) -&gt; bool</code><span class="nm-tip">True if the pattern matches anywhere in the text (a search).</span></a><a class="ns-method" href="regex-test.html"><code class="nm-sig">Regex.test(text, re) -&gt; bool</code><span class="nm-tip">Like matches, but reuses an already-compiled Regex.</span></a><a class="ns-method" href="regex-find.html"><code class="nm-sig">Regex.find(text, pattern) -&gt; Match</code><span class="nm-tip">The first match of the pattern in the text (a Match, or null if none).</span></a><a class="ns-method" href="regex-exec.html"><code class="nm-sig">Regex.exec(text, re) -&gt; Match</code><span class="nm-tip">Like find, but with an already-compiled Regex.</span></a><a class="ns-method" href="regex-next.html"><code class="nm-sig">Regex.next(text, re, from) -&gt; Match</code><span class="nm-tip">The next match at or after byte offset from — the basis of a find-all loop.</span></a><a class="ns-method" href="regex-replace.html"><code class="nm-sig">Regex.replace(text, pattern, replacement) -&gt; string</code><span class="nm-tip">Replace every match; the replacement expands \0..\9 group references.</span></a><a class="ns-method" href="regex-group.html"><code class="nm-sig">Regex.group(match, n) -&gt; string</code><span class="nm-tip">The text of capture group n (group 0 is the whole match); empty if unset.</span></a><a class="ns-method" href="regex-group_count.html"><code class="nm-sig">Regex.group_count(match) -&gt; int</code><span class="nm-tip">How many capture groups the match's pattern has.</span></a><a class="ns-method" href="regex-start.html"><code class="nm-sig">Regex.start(match, n) -&gt; int</code><span class="nm-tip">The start byte offset of group n, or -1 if it did not participate.</span></a><a class="ns-method" href="regex-end.html"><code class="nm-sig">Regex.end(match, n) -&gt; int</code><span class="nm-tip">The end byte offset of group n, or -1 if it did not participate.</span></a><a class="ns-method" href="regex-ok.html"><code class="nm-sig">Regex.ok(match) -&gt; bool</code><span class="nm-tip">True if the match succeeded (the Match is non-null).</span></a></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>