Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
agent / agent-regexBuilt by daveRuns on Liberas

Regular expressions

matches(pattern, input) -> whether the pattern matches anywhere in the input (ADR 0067): what JSON Schema's pattern means. A defined subset of ECMAScript's regular expressions, no flags, matched over Unicode scalar values (code points): literals; . (any code point but \n, \r, U+2028, U+2029); classes [...] and [^...] of code points, ranges lo-hi (lo <= hi, each a code point or an escape for one), \d \D \w \W \s \S inside them, a - first, last or beside a class standing for itself; [] matches nothing and [^] anything; escapes \d (0-9), \w (0-9 A-Z _ a-z), \s (ECMAScript's WhiteSpace and LineTerminator: U+0009–U+000D, U+0020, U+00A0, U+1680, U+2000–U+200A, U+2028, U+2029, U+202F, U+205F, U+3000, U+FEFF) and their complements \D \W \S, \b and \B (word boundary or not, a word character being \w; \b inside a class is U+0008), \n \t \r \f \v, \0 (not followed by a digit), \xHH, \uHHHH (not a surrogate), \cX (X a letter: its code point mod 32), and \ before any character that is not a letter or digit, standing for that character; ^ and $ (the input's start and end); groups (...), (?:...) and (?<name>...), all the same; alternation |, a branch may be empty; quantifiers * + ? {n} {n,} {n,m} (n <= m), each optionally followed by ? (lazy, which changes nothing here). A quantifier right after another, or on ^, $, \b, \B or nothing, is malformed. A { that does not start a quantifier, and ] and } outside a class, stand for themselves. Errors: "pattern is malformed" for anything else (an unbalanced ( or ), an unterminated class, a range out of order or ending in a class, an unknown or unfinished escape, a backreference, lookaround (?= (?! (?<= (?<!, flags (?i), a letter or digit escaped), then "pattern is too large" when the pattern's size is above 10,000, size being 1 per atom (a literal, class, ., ^, $, \b, \B), a sum over a concatenation or alternation, and a repetition's size multiplied by m for {n,m} (? is {0,1}, {n} is {n,n}), by n + 1 for {n,} (* is {0,}, + is {1,}), at least 1. Both are decided before the input is looked at; the pattern itself is any text. A match is a yes/no over the regular language, so a build may use any linear-time method; backtracking is not required to agree on anything.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init agent-regex --lang rust
cd agent-regex && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
agent-regex.wit
package root:component;

world root {
  export liberas:agent/regex@0.1.0;
}
package liberas:agent@0.1.0 {
  interface regex {
    matches: func(pattern: string, input: string) -> result<bool, string>;
  }
}
Test vectors68›
agent-regex.cases.json
[
  {
    "args": {
      "input": "anything",
      "pattern": ""
    }
  },
  {
    "args": {
      "input": "xxabcxx",
      "pattern": "abc"
    }
  },
  {
    "args": {
      "input": "ab c",
      "pattern": "abc"
    }
  },
  {
    "args": {
      "input": "abc",
      "pattern": "^abc$"
    }
  },
  {
    "args": {
      "input": "abcd",
      "pattern": "^abc$"
    }
  },
  {
    "args": {
      "input": "",
      "pattern": "^$"
    }
  },
  {
    "args": {
      "input": "a\nc",
      "pattern": "a.c"
    }
  },
  {
    "args": {
      "input": "a한c",
      "pattern": "a.c"
    }
  },
  {
    "args": {
      "input": "한글",
      "pattern": "^.{2}$"
    }
  },
  {
    "args": {
      "input": "한글",
      "pattern": "^.{3}$"
    }
  },
  {
    "args": {
      "input": "xyz",
      "pattern": "^[^a-c]+$"
    }
  },
  {
    "args": {
      "input": "xaz",
      "pattern": "^[^a-c]+$"
    }
  },
  {
    "args": {
      "input": "123-4567",
      "pattern": "^\\d{3}-\\d{4}$"
    }
  },
  {
    "args": {
      "input": "123-456",
      "pattern": "^\\d{3}-\\d{4}$"
    }
  },
  {
    "args": {
      "input": "me@x.io",
      "pattern": "^\\w+@\\w+\\.\\w+$"
    }
  },
  {
    "args": {
      "input": "a b",
      "pattern": "^\\S+$"
    }
  },
  {
    "args": {
      "input": "a b",
      "pattern": "\\s"
    }
  },
  {
    "args": {
      "input": "1.5",
      "pattern": "^[\\d.]+$"
    }
  },
  {
    "args": {
      "input": "a-b_c",
      "pattern": "^[\\w-]+$"
    }
  },
  {
    "args": {
      "input": "-a-",
      "pattern": "^[-a]+$"
    }
  },
  {
    "args": {
      "input": "ABC",
      "pattern": "^[\\x41-\\x43]+$"
    }
  },
  {
    "args": {
      "input": "é",
      "pattern": "^\\u00e9$"
    }
  },
  {
    "args": {
      "input": "\u0001",
      "pattern": "^\\cA$"
    }
  },
  {
    "args": {
      "input": "0",
      "pattern": "\\0"
    }
  },
  {
    "args": {
      "input": "1",
      "pattern": "^[\\D]$"
    }
  },
  {
    "args": {
      "input": "",
      "pattern": "^[]$"
    }
  },
  {
    "args": {
      "input": "\n",
      "pattern": "^[^]$"
    }
  },
  {
    "args": {
      "input": "]}",
      "pattern": "^]}$"
    }
  },
  {
    "args": {
      "input": "x{,5}",
      "pattern": "x{,5}"
    }
  },
  {
    "args": {
      "input": "a foo b",
      "pattern": "\\bfoo\\b"
    }
  },
  {
    "args": {
      "input": "afoob",
      "pattern": "\\bfoo\\b"
    }
  },
  {
    "args": {
      "input": "afoo",
      "pattern": "\\Bfoo"
    }
  },
  {
    "args": {
      "input": "dogs",
      "pattern": "^(cat|dog)s?$"
    }
  },
  {
    "args": {
      "input": "ababc",
      "pattern": "^(?:a|b)*c$"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "^(?<n>a)$"
    }
  },
  {
    "args": {
      "input": "",
      "pattern": "a|"
    }
  },
  {
    "args": {
      "input": "aaaa",
      "pattern": "^a{2,3}$"
    }
  },
  {
    "args": {
      "input": "aaaaa",
      "pattern": "^a{2,}$"
    }
  },
  {
    "args": {
      "input": "b",
      "pattern": "^a{0}b$"
    }
  },
  {
    "args": {
      "input": "aab",
      "pattern": "^a*?b$"
    }
  },
  {
    "args": {
      "input": "aaa",
      "pattern": "(a*)*b"
    }
  },
  {
    "args": {
      "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
      "pattern": "^(a+)+$"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(a{100}){100}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "("
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": ")"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "*a"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "a**"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "a{2}{3}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "^*"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "{2}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "a{3,2}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(?=a)"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(?<=a)b"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(?i)a"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(?<>a)"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(a)\\1"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "\\p{L}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "\\q"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "a\\"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "[a"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "[z-a]"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "[\\d-z]"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "\\x4"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "\\ud800"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "\\c1"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "a{10001}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(a{100}){101}"
    }
  },
  {
    "args": {
      "input": "a",
      "pattern": "(a{3,2}){99999}"
    }
  }
]
Versions (units)1›
  1. v1by davee497806cabstable 5.1.0latestconfirmed10/26/2026
Verification7›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 68 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 500,000,000 instructions.
  • Already built: a component that passes and uses at most 0.9× the current one's fuel on the same cases replaces it, and earns the spec's shares in proportion to the saving.
  • Found an input where the current component disagrees with the spec? Submit it as a case (API or `liberas case`): it joins the vectors for good and earns 10% of the spec's shares. A component that then passes replaces the broken one for 25%.