Regex from examples — paste positive matches + negative non-matches, get a regex that hits all positives and rejects all negatives, with multiple candidate patterns ranked by specificity.
- Runs locally
- Category Developer & DevOps
- Best for Formatting, validating, shrinking, or inspecting code-adjacent text.
Detected skeleton
What this tool does
Free in-browser regex inference tool. Instead of writing the regex yourself, paste a few example strings the regex should match (positive examples) and optionally a few strings it must not match (negative examples). The builder runs a column-aligned token classifier (letters / digits / whitespace / punctuation / unicode), discovers which positions are fixed across all positives and which are variable, and emits 3-5 candidate regexes ranked from tight to loose. Every candidate is verified against your negatives — any pattern that matches a negative is discarded automatically. Also includes one-click detection for 8 common preset patterns (email, URL, IPv4, ISO date, Chinese mobile, US zip, credit card, Chinese name) — if 3+ positives fit a preset, it shows up as a "Use this proven pattern" suggestion next to the inferred ones. Flag toggles (i / m / g / u), copy buttons for both raw and `/pattern/flags` form, and a "Try a new string" tester let you sanity-check before shipping the regex. 100% client-side, no third-party libraries, ~10 KB inference engine.
Tool details
- Input
- Text + Structured content
- The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
- Output
- Live result + Copy
- The result area focuses on usable output, with copy, download, or preview actions when supported.
- Privacy
- Browser-side processing
- The main tool logic does not call an external API, so inputs normally stay in the current tab.
- Save / share
- Shareable URL state
- Key settings are encoded in the URL so another person can reopen the same setup.
- Performance budget
- Initial JS <= 18 KB
- No WASM budget is declared, keeping the tool quick to open on mobile.
- Best fit
- Developer & DevOps · Developer
- Category and role tags drive related tools, internal links, and quick fit checks.
How to use
-
1. Input
Paste or drop your content into the tool panel.
-
2. Process
Click the button. All processing is local in your browser.
-
3. Copy / Download
Copy the result or download to disk in one click.
How Regex Builder from Examples fits into your work
Use it in the small gaps between coding, reviewing, debugging, and shipping.
Developer jobs
- Formatting, validating, shrinking, or inspecting code-adjacent text.
- Preparing snippets for documentation, tickets, commits, or handoff.
- Checking a small payload quickly without switching tools.
Developer checks
- Run irreversible transforms like minify or obfuscate on a copy.
- Keep secrets out of pasted snippets unless the tool explicitly stays local.
- Use your normal tests or linter before shipping transformed code.
Good next steps
These links move the current task into a more complete workflow.
- 1 Text Diff Compare two blocks of text — line-by-line additions, deletions, equal — colour highlighted, browser-only Open
- 2 Regex Tester Test JavaScript regex live — match highlighting, group capture, replace preview, flag toggles — browser-only Open
- 3 Regex Visualizer Regex visualizer — see your pattern as a railroad diagram + matching state machine, with capture groups highlighted. Open
Real-world use cases
Pull SKU codes out of a messy export without writing the regex
Your warehouse export has lines like `SKU-AX-00421-RED`, `SKU-AX-00422-BLU`, `SKU-BX-01193-BLK`. You need a regex to feed to a CLI parser. Paste those 3 lines as positives, paste `Total: 14 units` as a negative, hit Build. The first candidate comes back `SKU-[A-Z]{2}-\d{5}-[A-Z]{3}` — exact structure, rejects the total line, copy and paste into your pipeline. No counting digit positions by hand.
Catch all version strings in a mixed log
A log has `v1.2.3`, `v2.0.0`, `v10.4.21`, and you want a regex to extract them. Paste the three as positives. Paste `version 1` and `vNEXT` as negatives so the builder doesn't get sloppy. The tight candidate `v\d+\.\d+\.\d+` rejects both negatives and covers the variable-width major number — exactly what you wanted in under 10 seconds.
Build a regex for a custom log line shape
Your service emits `[2026-05-27 14:32:11] INFO user=alice action=login`. You have five of these from production. Paste them all as positives. The builder aligns the `[YYYY-MM-DD HH:MM:SS] LEVEL user=NAME action=VERB` skeleton, gives you the regex with named-ish capture groups for each variable field. Drop into Grafana / Loki query in 30 seconds.
Validate a mixed Chinese-number field
Your form receives values like `项目-001`, `项目-002`, `项目-127`, and someone occasionally types `Project-001` by mistake. Paste the Chinese ones as positives, the English one as a negative. The builder emits `项目-\d{3}` — locks the prefix to Chinese, rejects the English typo, your validation goes in.
Infer a regex for multilingual filenames
You're cleaning a download folder with names like `report_en.pdf`, `report_zh.pdf`, `report_ja.pdf`. Paste those as positives, paste `report.tmp` and `notes.pdf` as negatives. Candidate `report_[a-z]{2}\.pdf` comes back — 2-letter language code, .pdf extension, rejects both noise files. Bulk-rename script can now safely scan.
Extract a single URL parameter across query strings
You want to grab the `utm_source=X` value from request URLs like `?utm_source=newsletter&utm_medium=email`, `?utm_source=twitter&id=42`, `?other=foo&utm_source=hn_today`. Paste all three as positives, paste a URL without utm_source as a negative. The builder gives `utm_source=[\w_]+` — works regardless of parameter position.
Common pitfalls
Heuristic, not exhaustive. The builder only sees the examples you paste — if production data has a shape that wasn't in your samples (e.g. an SKU with 4 digits not 5), the regex will miss it. Always test on a larger real corpus before relying on the output.
We do NOT optimize the regex for runtime safety. Output is fine in JS / Go / Rust RE2, but feeding it into a naive backtracking engine (some PCRE configs, JS on adversarial input) can risk catastrophic backtracking. For untrusted text, prefer Go / Rust RE2.
Pasting only 1-2 positives gives the aligner nothing to compare. The result collapses into `.+` or `\S+`. Paste at least 3-5 varied positives so the algorithm can tell "fixed char at this column" from "variable field starts here".
Skipping negative examples produces over-permissive regexes. Negatives are where you tell the builder what to reject — 2-3 typos / near-misses are enough to eliminate the candidates that would accidentally accept wrong input.
Mixing unrelated shapes in positives (`alice@example.com` + `+1-555-0100`) breaks the aligner. It only finds a skeleton if there is one. Group examples by shape; build one regex per group.
Privacy
Token classifier, column-aligned skeleton finder, candidate generator, and negative-example verifier are all pure JavaScript that runs inside this browser tab. The positive and negative example strings you paste — which may contain real customer identifiers, internal IDs, log lines, anything — are never uploaded, never logged, never analyzed by us. The URL only remembers flag toggles and preset selection (not the example text itself) because shared links should not accidentally leak sensitive samples. Open DevTools → Network while you work; zero requests carry your examples. Works fully offline once cached.
FAQ
Tool combos
Folks in your role tend to reach for these alongside this tool.
- 555 Timer Calculator Astable f = 1.44/((R1+2R2)C) + monostable t = 1.1RC — pick R1, R2, C in Ω/kΩ and µF/nF, read frequency, duty cycle and pulse width — browser-only
- Add Line Numbers Number every line of pasted text — set start, step and separator, zero-pad to align, skip blanks, or strip numbers back off — browser-only
- AES Text Encryptor Encrypt & decrypt text with a password — AES-256-GCM + PBKDF2 via WebCrypto — 100% in your browser, nothing uploaded
- Affine Cipher Encoder & Decoder Encrypt and decrypt the ax+b affine cipher with live modular-inverse check, browser-only