# Regex From Examples for Any Script

Regex From Examples for Any Script is a tested SKILL.md that writes a JavaScript regular expression from a description plus lists of strings that must match and must not match, answered as JSON with the pattern and flags; an agent buys it once for $0.01 over x402.

- Page: https://aiskills402.com/skills/regex-from-examples
- Category: Code & Engineering (https://aiskills402.com/categories/code)
- Price: $0.01 once, USD-priced, paid in USDC on Base over x402. Price as loaded on this page. The 402 response your agent receives is authoritative.
- Version: 1.0.0
- Card (JSON): https://api.aiskills402.com/v1/skills/regex-from-examples

## Use it when

Writes a JavaScript regular expression from a description plus lists of strings that must match and must not match, answered as JSON with the pattern and flags. Knows the traps measured in Node 24 - \b and \w are ASCII-only even with the u flag, so \bдума\b never matches Cyrillic text and \w+ cuts "café" to "caf"; a word boundary for any script is a pair of lookarounds with \p{L} and the u flag. Anchors a validator so extra text around the value is rejected, adds the s or m flag when the input spans lines, and avoids nested quantifiers such as (\w+\s?)* that hang on a near-miss string. Use when asked to write, fix or tighten a regex, a validation pattern or a text-search pattern, especially for non-English text.

## Not for

Other regex flavours such as PCRE, Python or RE2 (their escapes and flags differ), parsing nested formats like HTML, and checking that an email or phone number really exists. It writes a JavaScript pattern for the strings you list, so cases you do not list are only as good as its reading of your description.

## Tested, honestly

Tested 2026-10-08.

- Strong model (claude-sonnet-5-5 (Claude Code alias "sonnet")): Wrote a regex that passes all 22 tasks: every must-match and must-not-match string, and long near-miss inputs inside 200 ms. Word boundaries in Cyrillic, Greek and accented text use lookarounds with Unicode properties and the u flag, validators are anchored, multi-line input gets the right flag, and repeated groups avoid nested quantifiers.
- Weak model (claude-haiku-5-5 (Claude Code alias "haiku")): Also 22 of 22, with the same kinds of pattern as Sonnet.

Note: Twenty-two tasks written by us, each with strings that must match, strings that must not, and long near-miss strings that must finish within 200 ms. About a third are plain tasks where the obvious regex is right; the rest set traps: word boundaries in Bulgarian, Greek and accented text, whole-value validators, multi-line input, names with letters outside A-Z, and patterns that hang on nested quantifiers. Each returned pattern was compiled and run against all strings. The JavaScript facts the skill states were measured in Node 24 on 8 October 2026. One run per model and task.

### With and without the skill

Tested 2026-10-08.

- Regexes that pass every string (22 tasks): Sonnet 22/22 with, 22/22 without; Haiku 22/22 with, 22/22 without.

No measurable gain on these tasks, for either model. The same request, asking for JSON only, went to both sides. When the task lists the strings that must match, both models already wrote lookarounds with p{L} and the u flag for Cyrillic and Greek instead of , anchored the validators and avoided nested quantifiers. What the skill adds is the measured notes on why those choices matter and a fixed JSON answer; it may help more when no examples are given or on weaker models than the two tested.

Same cases and the same checks with and without the skill. The cases are ours, written around what the skill is for; with a handful of cases, a difference of one or two is within noise.

Full summary: https://aiskills402.com/skills/regex-from-examples/tests

## Example

### English (claude-sonnet-5-5)

Before:

> Task: Find the Bulgarian word "дума" as a whole word, in any letter case, anywhere in a sentence. It must not match inside longer words. Must match (each string is one test input, shown as JSON):   "една дума тук"   "Дума е"   "дума"   "(дума)"   "Каква дума."   "ДУМА!" Must NOT match:   "думата"   "задума"   "думи"   "продумам"   "дума1"   "нищо"…

After:

> {"pattern": "(?<![\\p{L}\\p{N}_])дума(?![\\p{L}\\p{N}_])", "flags": "iu"}

## What is in the file

- The answer
- Where JavaScript surprises (measured in Node 24, 8 October 2026)
- Work in this order
- Short examples

## Languages

Any language

## How to buy

Agent (HTTP):

1. GET https://api.aiskills402.com/v1/skills/regex-from-examples/file without a payment header. The answer is 402 with a PAYMENT-REQUIRED header (x402 v2): exact amount, asset, network, recipient.
2. Sign `accepts[0]` with an x402 client (for example @x402/core + @x402/evm).
3. Repeat the GET with the signature in the PAYMENT-SIGNATURE header. The answer is 200 with the file, its sha256 and a re-download token.

Agent (MCP): https://mcp.aiskills402.com/mcp — free tools search_skills, get_skill, redownload_skill. Buying itself is over HTTP.

Full flow: https://aiskills402.com/docs

## The file

- Version: 1.0.0
- Size: 6.2 KB (6342 bytes)
- SHA-256: 77f1ec3198ae87e95cca5b699f1c107716ec388aa1c75f90320118602597174e
- Updated: 2026-10-08
- New versions are free through your re-download token.

## Versions

### 1.0.0 (2026-10-08)

First release: writes a JavaScript regular expression from a description and lists of strings that must and must not match, answered as JSON (pattern and flags). Covers what was measured in Node 24: \b and \w are ASCII-only even with the u flag, so word boundaries for Cyrillic, Greek and accented text are written with lookarounds and \p{L}; \p needs the u flag; validators are anchored; the s and m flags for multi-line input; and nested quantifiers that hang on near-miss strings are rewritten with a mandatory separator.

## License

Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Terms: https://aiskills402.com/docs#license

## FAQ

### What does the answer look like in practice?

JSON with a pattern and flags, ready for new RegExp(pattern, flags). Whole-value checks are anchored, text in Cyrillic, Greek or accented Latin is matched with Unicode properties and the u flag, and multi-line input gets the s or m flag. Nothing else is printed, so a script can parse the reply directly and hand it to the compiler without stripping a fence or a greeting.

### Why would a model get this wrong?

In JavaScript the \b and \w shortcuts only know ASCII letters, even with the u flag. A pattern like \bдума\b never matches Bulgarian text and \w+ cuts café to caf, so a check can return zero findings for months. We measured this in Node 24; the skill uses lookarounds with \p{L} instead. The same trap hides in word counters, linters and search boxes built for one alphabet.

### Does it protect against patterns that hang?

Yes. Nested quantifiers such as (\d+,?)+ took one second on 24 digits followed by a letter and double with every character. The skill writes the separator as required, which finishes a 100 000 character miss in milliseconds. Our test runs each pattern on long near-miss strings with a 200 ms limit. Greedy lazy tricks are not needed: the fix is structural, so the engine has only one way to split the input and cannot retry endlessly.

### Does it help Claude Sonnet?

Not on our 22 tasks. Sonnet and Haiku both passed all 22 with and without the skill, because the tasks list the strings that must match and both models already used lookarounds with \p{L} instead of \b. The skill gives you the measured JavaScript notes and a fixed JSON answer; do not expect a gain on tasks like ours.

## Related skills

- [Cron Schedule for Cloudflare Workers](https://aiskills402.com/skills/cron-schedule.md): $0.06 once
- [Text to JSON: Extract Data Without Guessing](https://aiskills402.com/skills/text-to-json.md): $0.05 once
- [SQLite Search Builder](https://aiskills402.com/skills/sqlite-search-builder.md): $0.01 once

## Measurement limits

- Models other than the two named above were not run.
- Each verdict comes from the test run on the date shown; the skill may have changed since (check the version).
- Full test inputs are not published here, only short excerpts of our own text.
- Results on your own texts, languages and domains can differ.

Offer note: Paid in USDC (USD-pegged) over x402 by an AI agent; one-time.
