> 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/regextract.md).

# regextract

**Syntax**

```programlisting
regextract (<string_value>, <pattern>)
```

**Description**

The `regextract()` function accepts a string and a regular expression, and it returns an array containing substrings that match the expression.

Cortex Query Language (XQL) uses [RE2](https://github.com/google/re2/wiki/Syntax) for its regular expression implementation. While capturing multiple groups is unsupported, capturing one group in queries is supported.

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.

{% hint style="info" %}

### Note

Capturing multiple groups is supported in Parsing Rules when using the [regexcapture](/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/functions/regexcapture.md) function.
{% endhint %}

**Examples**

<details>

<summary>Without a capturing group</summary>

Extract the `Account Name` from the `action_evtlog_message`. Use the [arrayindex](/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/functions/arrayindex.md) and [split](/cortex-xdr-3.x/cortex-xdr-3.x-documentation/cortex-xdr-xql/functions/split.md) functions to extract the actual account name from the array created by `regextract`.

```programlisting
dataset = xdr_data 
| fields action_evtlog_message as aem 
| filter aem != null 
| alter account_name = 
    arrayindex(
        split(
            arrayindex(
                regextract(aem, "Account Name:\t\t.*\r\n")
            ,0)
        , ":")
    ,1) 
| filter account_name != null 
| limit 10 
```

</details>

<details>

<summary>Using one capturing group</summary>

Extract from the `log_example` field all of the values included for the id objects.

```programlisting
dataset = xdr_data 
| limit 1
| alter
    log_example = "{\"events\":[{\"id\": \"1\", \"type\": \"process\", \"size\": 123, \"processID\": 40540},{\"id\": \"2\", \"type\": \"request\", \"size\": 456, \"srcOS\": \"MAC\"}],\"host\": \"LocalHost\",\"date\": {\"day\": 4, \"month\": 7, \"year\": 2024},\"tags\":[\"agent\", \"auth\", \"low\"]}"
| alter 
    one_capture_group_usage = regextract(log_example, "\"id\":\s*\"([^\"]+)\"")
| fields log_example, one_capture_group_usage
```

</details>


---

# 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/regextract.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.
