Combine regex patterns.

Intersect, subtract, union or complement patterns as sets. The result is a term you can pass to the next call, or read back as one regex pattern.

Try it.

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

Strings both patterns match, as one patternOPEN IN LIVE DEMO →
A =
B =
A B
PATTERN/api/v[12]/(.*/)?users/[0-9]+
Strings A matches and B does notOPEN IN LIVE DEMO →
A =
B =
A B
PATTERN.*\.(jpe?|pn)g
Strings either pattern matchesOPEN IN LIVE DEMO →
A =
B =
A B
PATTERN[0-9]
Strings the pattern does not matchOPEN IN LIVE DEMO →
A =
A
PATTERN.*[^a-z].*
A followed by BOPEN IN LIVE DEMO →
A =
B =
A · B
PATTERNabc.*de
A repeated 2 to 4 timesOPEN IN LIVE DEMO →
A =
A{}
PATTERN(abc){2,4}
OperationNotationAnswersReturns
intersectionABStrings matching all of the patterns.term
unionABStrings matching any of the patterns.term
differenceABStrings in A but not in B.term
complementAEvery string the pattern does not match.term
concatenationA · BPatterns joined in sequence.term
repeatA{n,m}The pattern repeated n to m times.term
determinizedfa(A)The same language as a deterministic FAIR, for a stable string order.term

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 });

// Strings both patterns match, as one pattern
const both = await client.intersection(
  Term.regex("/api/v[12]/.*"),
  Term.regex(".*/users/[0-9]+"),
);
await client.getPattern(both);
// "/api/v[12]/(.*/)?users/[0-9]+"

// Strings A matches and B does not
const noGif = await client.difference(
  Term.regex(".*\\.(jpe?g|png|gif)"),
  Term.regex(".*\\.gif"),
);
await client.getPattern(noGif);
// ".*\\.(jpe?|pn)g"

// Strings the pattern does not match
const rejected = await client.complement(noGif);

// Results are terms and can be passed to the next call.
// A term and its complement have no string in common:
await client.isEmpty(await client.intersection(noGif, rejected));
// true