# xarray.DataArray.str.extractall

#### DataArray.str.extractall(pat, group_dim, match_dim, case=None, flags=0)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L2115-L2291)

Extract all matches of capture groups in the regex pat as new
dimensions in a DataArray.

For each string in the DataArray, extract groups from all matches
of regular expression pat.
Equivalent to applying re.findall() to all the elements in the DataArray
and splitting the results across dimensions.

If pat is array-like, it is broadcast against the array and applied
elementwise.

* **Parameters:**
  * **pat** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`re.Pattern`](https://docs.python.org/3/library/re.html#re.Pattern)) – A string containing a regular expression or a compiled regular
    expression object. If array-like, it is broadcast.
  * **group_dim** ([hashable](../user-guide/terminology.html.md#term-name)) – Name of the new dimensions corresponding to the capture groups.
    This dimension is added to the new DataArray first.
  * **match_dim** ([hashable](../user-guide/terminology.html.md#term-name)) – Name of the new dimensions corresponding to the matches for each group.
    This dimension is added to the new DataArray second.
  * **case** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – If True, case sensitive.
    Cannot be set if pat is a compiled regex.
    Equivalent to setting the re.IGNORECASE flag.
  * **flags** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `0`) – Flags to pass through to the re module, e.g. re.IGNORECASE.
    see [compilation-flags](https://docs.python.org/3/howto/regex.html#compilation-flags).
    `0` means no flags. Flags can be combined with the bitwise or operator `|`.
    Cannot be set if pat is a compiled regex.
* **Returns:**
  **extracted** (`same type as values` or `object array`)
* **Raises:**
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – pat has no capture groups.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – case is set when pat is a compiled regular expression.
  * [**KeyError**](https://docs.python.org/3/builtins/exceptions.html#KeyError) – Either of the given dimensions is already present in the DataArray.
  * [**KeyError**](https://docs.python.org/3/builtins/exceptions.html#KeyError) – The given dimensions names are the same.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('e115b12e-9de6-4a43-b2af-df6d5560505f','14bd7170-e157-437e-a5d5-3b36a2a13fe5','8ffd43a8-5079-4eab-9bc5-d4c539d0ed6f','../lite/tree/../notebooks/index.html?path=3ebe3c15_ccb4_4f4f_a9fd_69b8f6582b87.ipynb','None')">Try it in your browser!</button></div>

Create a string array

```pycon
>>> value = xr.DataArray(
...     [
...         [
...             "a_Xy_0",
...             "ab_xY_10-bab_Xy_110-baab_Xy_1100",
...             "abc_Xy_01-cbc_Xy_2210",
...         ],
...         [
...             "abcd_Xy_-dcd_Xy_33210-dccd_Xy_332210",
...             "",
...             "abcdef_Xy_101-fef_Xy_5543210",
...         ],
...     ],
...     dims=["X", "Y"],
... )
```

Extract matches

```pycon
>>> value.str.extractall(
...     r"(\w+)_Xy_(\d*)", group_dim="group", match_dim="match"
... )
<xarray.DataArray (X: 2, Y: 3, group: 3, match: 2)> Size: 1kB
array([[[['a', '0'],
         ['', ''],
         ['', '']],

        [['bab', '110'],
         ['baab', '1100'],
         ['', '']],

        [['abc', '01'],
         ['cbc', '2210'],
         ['', '']]],


       [[['abcd', ''],
         ['dcd', '33210'],
         ['dccd', '332210']],

        [['', ''],
         ['', ''],
         ['', '']],

        [['abcdef', '101'],
         ['fef', '5543210'],
         ['', '']]]], dtype='<U7')
Dimensions without coordinates: X, Y, group, match
```

<div id="8ffd43a8-5079-4eab-9bc5-d4c539d0ed6f" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e115b12e-9de6-4a43-b2af-df6d5560505f','8ffd43a8-5079-4eab-9bc5-d4c539d0ed6f')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e115b12e-9de6-4a43-b2af-df6d5560505f','8ffd43a8-5079-4eab-9bc5-d4c539d0ed6f')">Open In Tab</button></div><div id="14bd7170-e157-437e-a5d5-3b36a2a13fe5" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.str.extract`](xarray.DataArray.str.extract.html.md#xarray.DataArray.str.extract), [`DataArray.str.findall`](xarray.DataArray.str.findall.html.md#xarray.DataArray.str.findall), [`re.compile`](https://docs.python.org/3/library/re.html#re.compile), [`re.findall`](https://docs.python.org/3/library/re.html#re.findall), [`pandas.Series.str.extractall`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.extractall.html#pandas.Series.str.extractall)
