jed

Pattern matching

jed offers three ways to match text against a pattern: SQL LIKE / ILIKE, the regular-expression operators ~ ~* !~ !~*, and the regexp_replace / regexp_match functions.

LIKE / ILIKE

LIKE is the SQL wildcard match: % matches any run of characters, _ matches exactly one. ILIKE is the case-insensitive form. The match is by Unicode code point.

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

Regular expressions

The ~ operator is TRUE when the pattern matches somewhere in the subject (it is unanchored — anchor with ^ / $ for a whole-string match). ~* is case-insensitive, and !~ / !~* are their negations.

jed’s regex flavor is its own, deliberately not PostgreSQL-compatible: it is a clean RE2-style subset run by a linear-time engine, so it is immune to catastrophic-backtracking (“ReDoS”) attacks — a pattern that would hang a backtracking engine runs in linear time here. SIMILAR TO, backreferences, and lookaround are intentionally absent.

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

The pattern surface: literals, . (any code point except newline), character classes [...] / [^...], the shorthands \d \w \s (and \D \W \S), anchors ^ $, alternation |, groups (...) / (?:...), and the quantifiers * + ? {n} {n,} {n,m} (each with a lazy ?-suffixed form). Matching is greedy and leftmost-first.

Case-insensitive matching:

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

Negation — accounts whose address has no + tag:

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

Linear-time by construction

The classic catastrophic-backtracking pattern (a+)+$ is harmless here — it matches (or fails) in time proportional to the input, never exponentially:

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

regexp_replace

regexp_replace(source, pattern, replacement [, flags]) replaces the first match (or all matches with the g flag). The replacement is a template: \1\9 splice in capture groups, \& the whole match, and \\ a literal backslash.

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

Reordering with capture groups:

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

regexp_match

regexp_match(source, pattern [, flags]) returns a text[] of the first match’s capture groups (or the whole match when the pattern has no group), or NULL when there is no match.

Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

The i flag makes any of these case-insensitive; for regexp_replace, g makes it global. A malformed pattern raises 2201B (invalid_regular_expression).

jed — an embeddable, strictly-typed SQL database.