ForHosting KIT · Developer Utilities

Extract regex named capture groups

Paste a pattern such as (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) and get its named groups in order: year, month and day. The pattern is checked but never run, ready for documentation or replacement tokens. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Pattern
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
You get
Named groups
year, month, day
Quantity
3

<name>...) over numbered groups alone.

What named capture groups are for

A named capture group is written as an opening parenthesis, a question mark, a name between angle brackets, then the subpattern and a closing parenthesis, as in (?<year>\d{4}). When a match succeeds, those names become readable labels, so code reads the year by its name instead of guessing which numbered group holds it. That is why long patterns in shared libraries, form parsers and validators tend to name their groups: anyone who inherits the pattern can see what each part captures.

Listing the names without running a match

Before you write replacement templates, generate types for a validator or offer tokens such as $<name> in an editing screen, you need the exact list of names a pattern defines. This tool checks that the pattern is valid and reads the names from left to right, in the order they are declared. Unnamed groups and non-capturing groups are left out, lookbehind assertions are not mistaken for names, and characters inside square brackets never produce false entries. A pattern with no named groups simply returns an empty list.

What named capture groups are and why listing them helps

In ECMAScript regular expressions, a named capture group is written as an opening parenthesis, a question mark, a less-than sign, an identifier, a greater-than sign, then the subpattern and a closing parenthesis: for example open-paren question-mark less-than year greater-than backslash-d open-brace four close-brace close-paren. When a match succeeds, the engine exposes those names on the groups object so callers read match.groups.year instead of match[1].

Listing the names without running a match is useful whenever you document a pattern, generate TypeScript types for a validator, or build a UI that offers replacement tokens like dollar-less-than name greater-than. Unnamed capturing groups and non-capturing groups are ignored for the name list. Lookbehind assertions that start with question-mark less-than equals or question-mark less-than exclamation are not treated as named groups.

Character classes and escaped parentheses never contribute false positives, so a literal string containing the characters of a named-group opener inside brackets does not appear in the result.

Auto-document regex libraries

Generate a table of named capture group identifiers for every pattern in a shared library so docs stay in sync with the source.

Are lookbehinds treated as named groups?

No. Assertions written as (? <=...) or (? <!...) are skipped. Only (? <name>...) capture groups appear in the list.

What happens if the pattern has no named groups?

You get an empty list and a count of zero, not an error. Only a pattern that the regular expression engine itself rejects, for example one with broken syntax, is refused.

Does the tool run the pattern against sample text?

No. It only checks that the pattern is valid and reads the group names from left to right, in the order they are declared. Nothing is matched, so no sample text is needed.

Can two groups share the same name?

No. Current engines reject duplicate names when they compile the pattern, so the tool reports the problem with a clear message instead of returning a list with the same name twice.

Are unnamed groups or characters in brackets counted?

No. Plain numbered groups and non-capturing groups are left out of the list, and characters inside square brackets or escaped parentheses never produce a false name, even when they look like a group opener.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev/regex-named-group-extract

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev/regex-named-group-extract \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pattern":"(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})"}'
{
  "pattern": "(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.regex_named_group_extract",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Named capture groups turn opaque match indexes into readable field names such as year, month, and email_local, which is why modern regex libraries and API validators prefer (? When you inherit a long pattern, generate documentation, or wire a form parser, you often need the list of names the pattern actually defines before you write replacement templates or map groups into JSON. This capability accepts a single ECMAScript regex body, validates that the pattern compiles, and returns the ordered list of named capture group identifiers it declares. Patterns with no named groups succeed with an empty list rather than an error; only syntax that the engine rejects fails with invalid_input.

What named capture groups are and why listing them helps

This endpoint does not execute the regex against sample text; it only validates the pattern and extracts the names in left-to-right definition order. Duplicate names fail at compile time on current ECMAScript engines and surface as invalid_input with a clear message.

Input contract, response shape, and error behaviour

The value must be a non-empty string of at most ten thousand characters. Empty pattern, missing pattern, or a non-string type fail validation before compilation. POST a JSON body with one required string field: pattern, the regular expression body without surrounding slashes. On success the body echoes pattern, returns named_groups as a string array in definition order, count as the array length, and has_named_groups as a boolean convenience flag. Example: the date pattern with three named groups for year, month, and day yields count three and has_named_groups true. A simple word matcher such as backslash-w plus with no named groups yields an empty named_groups array, count zero, and has_named_groups false—still a successful call, because the pattern is valid. Use the free browser tool for quick inspection; use the API when CI pipelines or CMS plugins need a stable machine-readable list of group names for every pattern in a config file.

Where extracting named groups earns its keep

Documentation sites and style guides that publish regex libraries can auto-generate a table of group names for each pattern without hand-maintaining a parallel list that drifts. Form builders and log parsers that accept user-supplied patterns can refuse templates that reference dollar-less-than name greater-than tokens absent from the pattern, reducing runtime surprises. Failed validation does not consume balance. Security review checklists often ask which fields a validation regex captures; returning the name list from a tiny parse API is cheaper than standing up a full regex debugger for every pull request.

Validate replacement templates

Before saving a replace rule that uses $<name> tokens, confirm each name exists in the pattern’s named_groups list.

CI checks for form and log parsers

Fail a pipeline when a config regex claims to capture email or order_id but defines no matching named group.

How do I extract named capture groups from a regex?

Send a JSON body with pattern set to the ECMAScript regex body (no slashes). The API returns named_groups in definition order plus count and has_named_groups.

What happens if the pattern is invalid?

The task fails with invalid_input and a message that includes the engine error. Invalid patterns are not billed.

Does a pattern without named groups return an error?

No. Valid patterns with only numbered or non-capturing groups succeed with an empty named_groups array and count zero.

What does extracting regex named groups cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →