r""" Extract the first match of capture groups in the regex pat as a new dimension in a DataArray. For each string in the DataArray, extract groups from the first match of regular expression pat. If `pat` is array-like, it is broadcast against the array and
(
self,
pat: str | bytes | Pattern | Any,
dim: Hashable,
case: bool | None = None,
flags: int = 0,
)
| 1953 | return self._apply(func=func, func_args=(pat, repl, n)) |
| 1954 | |
| 1955 | def extract( |
| 1956 | self, |
| 1957 | pat: str | bytes | Pattern | Any, |
| 1958 | dim: Hashable, |
| 1959 | case: bool | None = None, |
| 1960 | flags: int = 0, |
| 1961 | ) -> T_DataArray: |
| 1962 | r""" |
| 1963 | Extract the first match of capture groups in the regex pat as a new |
| 1964 | dimension in a DataArray. |
| 1965 | |
| 1966 | For each string in the DataArray, extract groups from the first match |
| 1967 | of regular expression pat. |
| 1968 | |
| 1969 | If `pat` is array-like, it is broadcast against the array and applied |
| 1970 | elementwise. |
| 1971 | |
| 1972 | Parameters |
| 1973 | ---------- |
| 1974 | pat : str or re.Pattern or array-like of str or re.Pattern |
| 1975 | A string containing a regular expression or a compiled regular |
| 1976 | expression object. If array-like, it is broadcast. |
| 1977 | dim : hashable or None |
| 1978 | Name of the new dimension to store the captured strings in. |
| 1979 | If None, the pattern must have only one capture group and the |
| 1980 | resulting DataArray will have the same size as the original. |
| 1981 | case : bool, default: True |
| 1982 | If True, case sensitive. |
| 1983 | Cannot be set if `pat` is a compiled regex. |
| 1984 | Equivalent to setting the `re.IGNORECASE` flag. |
| 1985 | flags : int, default: 0 |
| 1986 | Flags to pass through to the re module, e.g. `re.IGNORECASE`. |
| 1987 | see `compilation-flags <https://docs.python.org/3/howto/regex.html#compilation-flags>`_. |
| 1988 | ``0`` means no flags. Flags can be combined with the bitwise or operator ``|``. |
| 1989 | Cannot be set if `pat` is a compiled regex. |
| 1990 | |
| 1991 | Returns |
| 1992 | ------- |
| 1993 | extracted : same type as values or object array |
| 1994 | |
| 1995 | Raises |
| 1996 | ------ |
| 1997 | ValueError |
| 1998 | `pat` has no capture groups. |
| 1999 | ValueError |
| 2000 | `dim` is None and there is more than one capture group. |
| 2001 | ValueError |
| 2002 | `case` is set when `pat` is a compiled regular expression. |
| 2003 | KeyError |
| 2004 | The given dimension is already present in the DataArray. |
| 2005 | |
| 2006 | Examples |
| 2007 | -------- |
| 2008 | Create a string array |
| 2009 | |
| 2010 | >>> value = xr.DataArray( |
| 2011 | ... [ |
| 2012 | ... [ |