RegEx vs STRling

Keep RegEx power. Improve the interface.

Regular expressions are compact, fast, and deeply embedded in software. STRling does not replace that engine; it gives people a clearer way to build patterns for it.

The pressure point

Symbol density grows faster than understanding

Short RegEx is often ideal. As requirements add choices, optional pieces, captures, and assertions, the same compactness can make review and change harder.

01

Reading

A maintainer must decode punctuation, precedence, and capture structure before understanding domain intent.

02

Changing

Editing a dense string can accidentally alter grouping, escaping, or quantifier scope.

03

Discovering

RegEx syntax rarely appears in host-language autocomplete, while named APIs and signatures can.

Source-documented comparison

The pattern says what each part means

The TypeScript 4.0.3 Preview adapter records literal strings and reusable Pattern values as Simply operations.

Composable STRling
import * as s from '@strling-lang/strling/simply';

const digit = s.between('0', '9');
const prefix = digit.rep(1, 3);
const area = digit.rep(3);
const subscriber = digit.rep(4);
const separator = s.may(s.inChars('-', '.', ' '));
const phone = s.merge(prefix, separator, area, separator, subscriber);
/(?:[0-9]){1,3}(?:[\x20\x2d.])?(?:[0-9]){3}(?:[\x20\x2d.])?(?:[0-9]){4}/u

This example shows an unanchored phone-like shape and the exact ECMAScript 2024 artifact rendered as a JavaScript RegExp literal. Naming prefix,area, and subscribermakes their roles available to review and reuse.

Composition model

A regular expression becomes a small program

Sequence and alternatives

merge(...) places pieces in order. anyOf(...) in TypeScript and any_of(...) in Python express alternatives.

Optionality and repetition

may(...) makes a piece optional. Static constructors accept repetition bounds, and Pattern values expose repetition methods.

Captures with intent

capture(...) creates a numbered group; group(name, ...) gives extracted text a stable domain name.

Assertions without punctuation recall

ahead, notAhead, behind, and notBehind expose lookaround intent.

Cross-language concepts

One mental model, idiomatic naming

Python uses names such as any_of and in_chars; TypeScript uses anyOf and inChars. The concepts stay recognizable without pretending every language is identical.

A measured claim

Safety depends on the binding and target

STRling validates API inputs and the public specification defines diagnostics for unsupported features and engine incompatibility. The canonical compiler analyzes requests and lowers them for an exact target profile. The target engine executes the artifact.

Read the portability model

Use STRling when the pattern deserves a name

For a tiny one-off expression, raw RegEx may be the clearest choice. Reach for STRling when a pattern carries business meaning, will evolve, needs review, or should be shared across a codebase.