Analyze regex patterns.

Compare two patterns, check containment, count the strings a pattern matches and get its shortest and longest match length. Each answer is computed on the automaton and covers every string the pattern can match.

Try it.

Each card calls the real API. Edit the patterns and compute. No signup.

Same language?OPEN IN LIVE DEMO →
A =
B =
A B
BOOLEANtrue
Is every match of A also a match of B?OPEN IN LIVE DEMO →
A =
B =
A B
BOOLEANtrue
Number of strings the pattern matchesOPEN IN LIVE DEMO →
A =
|A|
COUNT<Cardinality::Integer(1048576)>
Shortest and longest match lengthOPEN IN LIVE DEMO →
A =
len(A)
RANGE<Length: min=9, max=10>
OperationNotationAnswersReturns
cardinality|A|How many distinct strings does the pattern match?count | ∞
lengthlen(A)Shortest and longest possible match.[min, max]
empty / totalA = ∅ · A = Σ*Matches nothing at all? Matches everything?boolean
equivalentABSame language, regardless of syntax?boolean
subsetABIs every match of A also a match of B?boolean
patternre(A)A compact, human-readable regex for any term.regex
empty_stringA = {ε}Matches only the empty string?boolean
deterministicdet(A)Is the automaton deterministic? A stable string order requires it.boolean
dotdot(A)The automaton as a Graphviz DOT graph, ready to render.dot

In code.

The main operations on this page, called through the official SDK.

import { RegexSolverClient, Term } from 'regexsolver';

const client = new RegexSolverClient({ apiToken: process.env.REGEXSOLVER_API_TOKEN });

// Same language, different syntax?
await client.equivalent(Term.regex("(abcd|abef)"), Term.regex("ab(cd|ef)"));
// true

// Is every match of A also a match of B?
await client.subset(Term.regex("beta-[0-9]{4}"), Term.regex("(alpha|beta)-[0-9]{4}"));
// true

// Number of strings the pattern matches
await client.getCardinality(Term.regex("[a-f0-9]{5}"));
// 1048576

// Shortest and longest possible match
await client.getLength(Term.regex("(alpha|beta|prod)-[a-z0-9]{4}"));
// [9, 10]

// Every match of A is a match of B when A minus B is empty
const gap = await client.difference(Term.regex("(abcd|abef)"), Term.regex("ab(cd|ef)"));
await client.isEmpty(gap);
// true