> For the complete documentation index, see [llms.txt](https://upsolver.gitbook.io/content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/regular-expressions/regex_named_groups.md).

# REGEX\_NAMED\_GROUPS

Matches the regular expression on the input string. Returns the record with field names and group names.

## Syntax

```sql
REGEX_NAMED_GROUPS(pattern, allMatches, filterEmpty, input)
```

## Arguments

<table><thead><tr><th>Name</th><th width="169">Type</th><th>Description</th><th>Default Value</th></tr></thead><tbody><tr><td>pattern</td><td>string</td><td>Regular Expression Pattern</td><td></td></tr><tr><td>allMatches</td><td>Boolean</td><td>Return all the matches of the pattern, and not only the first one</td><td>false</td></tr><tr><td>filterEmpty</td><td>Boolean</td><td>Filter out empty matches</td><td>false</td></tr><tr><td>input</td><td>string</td><td></td><td></td></tr></tbody></table>

## Examples

<table><thead><tr><th>pattern</th><th>allMatches</th><th width="155">filterEmpty</th><th>input</th><th>Output</th></tr></thead><tbody><tr><td>'^(?:(?.<em>?):/)?/?(?[^:/\s]+)(?::(?\d</em>))?(?:(/\w+)<em>/)(?[\w-.]+[^#?\s]+)(?:.</em>)?$'</td><td>false</td><td>false</td><td>'https://www.domain.com/page.html'</td><td>{scheme: <code>https</code>, domain: <code>www.domain.com</code>, port: null, page: <code>page.html</code>}</td></tr><tr><td>'^(?:(?.<em>?):/)?/?(?[^:/\s]+)(?::(?\d</em>))?(?:(/\w+)<em>/)(?[\w-.]+[^#?\s]+)(?:.</em>)?$'</td><td>false</td><td>false</td><td>'http://www.domain.com:8080/page.html'</td><td>{scheme: <code>http</code>, domain: <code>www.domain.com</code>, port: <code>8080</code>, page: <code>page.html</code>}</td></tr><tr><td>'^(?\d*)$'</td><td>false</td><td>false</td><td>'123'</td><td>{digits: <code>123</code>}</td></tr><tr><td>'^(?\d*)$'</td><td>false</td><td>false</td><td>'foo'</td><td>null</td></tr><tr><td>'^(?\d*)$'</td><td>false</td><td>false</td><td>''</td><td>{digits: ``}</td></tr><tr><td>'^(?\d*)$'</td><td>false</td><td>true</td><td>''</td><td>null</td></tr><tr><td>'\bwww.(?[^.]*).com\b'</td><td>true</td><td>false</td><td>'www.upsolver.com'</td><td>{domain: <code>upsolver</code>}</td></tr><tr><td>'\bwww.(?[^.]*).com\b'</td><td>true</td><td>false</td><td>'www.a.com www.b.com'</td><td>[{domain: <code>a</code>}, {domain: <code>b</code>}]</td></tr><tr><td>'\bwww.(?[^.]*).com\b'</td><td>false</td><td>false</td><td>'www.a.com www.b.com'</td><td>{domain: <code>a</code>}</td></tr></tbody></table>

### Transformation job example

#### SQL

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT pattern, allMatches, filterEmpty, input,
        REGEX_NAMED_GROUPS('^(?:(?<scheme>.*?):\/)?\/?(?<domain>[^:\/\s]+)(?::(?<port>\d*))?(?:(\/\w+)*\/)(?<page>[\w\-\.]+[^#?\s]+)(?:.*)?$', false, false, input) AS Output
    FROM default_glue_catalog.upsolver_samples.orders_raw_data
    LET pattern = '^(?:(?<scheme>.*?):\/)?\/?(?<domain>[^:\/\s]+)(?::(?<port>\d*))?(?:(\/\w+)*\/)(?<page>[\w\-\.]+[^#?\s]+)(?:.*)?$',
        allMatches = false,
        filterEmpty = false,
        input = 'https://www.domain.com/page.html'
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

#### Query result

<table><thead><tr><th width="175">pattern</th><th width="122">allMatches</th><th width="130">filterEmpty</th><th>input</th><th>Output</th></tr></thead><tbody><tr><td>'^(?:(?.<em>?):/)?/?(?[^:/\s]+)(?::(?\d</em>))?(?:(/\w+)<em>/)(?[\w-.]+[^#?\s]+)(?:.</em>)?$'</td><td>false</td><td>false</td><td>'https://www.domain.com/page.html'</td><td>{scheme: <code>https</code>, domain: <code>www.domain.com</code>, port: null, page: <code>page.html</code>}</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/regular-expressions/regex_named_groups.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
