> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/functions/regexcapture.md).

# regexcapture

{% hint style="info" %}

### Important

The `regexcapture()` function is only supported in the XQL syntax for Parsing Rules.
{% endhint %}

**Syntax**

```programlisting
regexcapture(<field>, "<pattern>")
```

**Description**

In Parsing Rules, the `regexcapture()` function is used to extract data from fields using regular expression named groups from a given string and returns a JSON object with captured groups. This function can be used in any section of a Parsing Rule. The `regexcapture()` function is useful when the regex pattern is not identical throughout the log, which is required when using the [regextract](/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/functions/regextract.md) function.

XQL uses [RE2](https://github.com/google/re2/wiki/Syntax) for its regular expression implementation. When using the `(?i)` syntax for case-insensitive mode in your query, this syntax should be added only once at the  beginning of the inline regular expression.

**Example**

Parsing Rule to ceate a dataset called `my_regexcapture_test`, where the vendor and product that the specified Parsing Rules applies to is called `regexcapture_vendor` and `regexcapture_product`. The output results includes a new field called `regexcaptureResult`, which extract data from the `_raw_log` field using regular expression named groups as defined and returns the captured groups.

Parsing Rule:

```programlisting
[INGEST:vendor="regexcapture_vendor", product="regexcapture_product", target_dataset="my_regexcapture_test"]
alter regexcaptureResult = regexcapture(_raw_log,"^(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (?P<user>\w+) \[(?P<timestamp>.+)\] (?P<request>.+) (?P<status>\d{3}) (?P<bytes>\d+)");
```

Log:

```programlisting
192.168.1.1 - john [10/Mar/2024:12:34:56 +0000] GET /index.html HTTP/1.1 200 1234
```

XQL Query:

For the `my_regexcapture_test` dataset, returns the `regexcaptureResult` field output.

```programlisting
dataset = my_regexcapture_test 
| fields regexcaptureResult
```

regexcaptureResult field output:

```programlisting
{
  "ip": "192.168.1.1",
  "user": "john",
  "timestamp": "10/Mar/2024:12:34:56 +0000",
  "request": "GET /index.html HTTP/1.1",
  "status": "200",
  "bytes": "1234"
}
```


---

# 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://cortex-docs.paloaltonetworks.com/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/functions/regexcapture.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.
