Generate strings from a regex.

Distinct strings that match a pattern, in a fixed order, paginated with limit and offset, with optional length and character-set bounds.

Try it.

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

Strings the pattern matchesOPEN IN LIVE DEMO →
A =
strings(A, limit: , offset: )
STRINGS["beta-0000", "beta-0001", "beta-0002", "beta-0003", "beta-0004"]
Page through the results with offsetOPEN IN LIVE DEMO →
A =
strings(A, limit: , offset: )
STRINGS["abcde", "abcabc"]
Only strings within a length window
A =(ab|cde)*
strings(A, limit: 5, minLength: 4, maxLength: 6)
STRINGS["abab", "cdeab", "abcde", "ababab", "cdecde"]
Every string of a finite patternOPEN IN LIVE DEMO →
A =
strings(A, limit: , offset: )
STRINGS["000", "001", "010", "011", "100", "101", "110", "111"]
OperationNotationAnswersReturns
strings{s ∈ A}Distinct strings the pattern matches, paginated by limit/offset.string[]

Parameters

ParameterValuesMeaning
limit1 to 100Maximum number of distinct strings to return in the call. The example cards above and the live demo cap it at 10.
offsetintegerStrings to skip before collecting, which is how you paginate.
minLengthintegerLower bound of the length window; excluded strings never consume offset positions.
maxLengthintegerUpper bound of the length window.
pathOrdersweep · interleave · shuffledWhich paths of the language are expanded first.
characterOrderascending · shuffledHow each position is filled from its character range.
seedintegerDraws both shuffled orders, so a shuffled run stays reproducible.
charsetcharacter classRestricts generation to a character class such as [a-z]; paths needing anything else are dropped.

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 });
const term = Term.regex("(alpha|beta|prod)-[a-z0-9]{4}");

// Distinct strings the pattern matches
await client.generateStrings(term, 5, 0);
// ["beta-0000", "beta-0001", "beta-0002", "beta-0003", "beta-0004"]

// Page through the language with offset. Pages only line up on a
// deterministic term, so determinize once first.
const bits = await client.determinize(Term.regex("[01]{3}"));
const all = [];
for (let offset = 0; ; offset += 3) {
  const page = await client.generateStrings(bits, 3, offset);
  all.push(...page);
  if (page.length < 3) break;
}
// ["000", "001", "010"], then ["011", "100", "101"], then ["110", "111"]

// Only strings within a length window
await client.generateStrings(Term.regex("(ab|cde)*"), 5, 0, { minLength: 4, maxLength: 6 });
// ["abab", "cdeab", "abcde", "ababab", "cdecde"]

// Restrict generation to a character class
await client.generateStrings(Term.regex("[a-z]{3}"), 5, 0, { charset: "[a-c]" });

// Shuffled order, reproducible with a seed
await client.generateStrings(term, 5, 0, {
  pathOrder: "shuffled", characterOrder: "shuffled", seed: 42,
});