Skip to content

daft.functions.regexp_split#

regexp_split #

regexp_split(expr: Expression, pattern: str | Expression) -> Expression

Splits each string on the given regex pattern, into a list of strings.

Parameters:

Name Type Description Default
expr Expression

The expression to split.

required
pattern str | Expression

The pattern on which each string should be split, or a column to pick such patterns from.

required

Returns:

Name Type Description
Expression Expression

A List[String] expression containing the string splits for each string in the column.

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import regexp_split
>>>
>>> df = daft.from_pydict({"data": ["daft.distributed...query", "a.....b.c", "1.2...3.."]})
>>> df.with_column("split", regexp_split(df["data"], r"\.+")).collect()
╭──────────────────────────┬────────────────────────────╮
│ data                     ┆ split                      │
│ ---                      ┆ ---                        │
│ String                   ┆ List[String]               │
╞══════════════════════════╪════════════════════════════╡
│ daft.distributed...query ┆ [daft, distributed, query] │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ a.....b.c                ┆ [a, b, c]                  │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1.2...3..                ┆ [1, 2, 3, ]                │
╰──────────────────────────┴────────────────────────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
def regexp_split(expr: Expression, pattern: str | Expression) -> Expression:
    r"""Splits each string on the given regex pattern, into a list of strings.

    Args:
        expr: The expression to split.
        pattern: The pattern on which each string should be split, or a column to pick such patterns from.

    Returns:
        Expression: A List[String] expression containing the string splits for each string in the column.

    Examples:
        >>> import daft
        >>> from daft.functions import regexp_split
        >>>
        >>> df = daft.from_pydict({"data": ["daft.distributed...query", "a.....b.c", "1.2...3.."]})
        >>> df.with_column("split", regexp_split(df["data"], r"\.+")).collect()
        ╭──────────────────────────┬────────────────────────────╮
        │ data                     ┆ split                      │
        │ ---                      ┆ ---                        │
        │ String                   ┆ List[String]               │
        ╞══════════════════════════╪════════════════════════════╡
        │ daft.distributed...query ┆ [daft, distributed, query] │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ a.....b.c                ┆ [a, b, c]                  │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 1.2...3..                ┆ [1, 2, 3, ]                │
        ╰──────────────────────────┴────────────────────────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)
    """
    return Expression._call_builtin_scalar_fn("regexp_split", expr, pattern)