polars.Expr.bin.find_many#
- Expr.bin.find_many(
- patterns: IntoExpr,
- *,
- ascii_case_insensitive: bool = False,
- overlapping: bool = False,
- leftmost: bool = False,
Use the Aho-Corasick algorithm to find many matches.
Returns the byte offset of the start of each match.
Warning
This functionality is considered experimental. It may be removed or changed at any point without it being considered a breaking change.
- Parameters:
- patterns
Binary patterns to search.
- ascii_case_insensitive
Enable ASCII-aware case-insensitive matching. When this option is enabled, searching will be performed without respect to case for ASCII letters (a-z and A-Z) only.
- overlapping
Whether matches may overlap.
- leftmost
Guarantees in case there are overlapping matches that the leftmost match is used. In case there are multiple candidates for the leftmost match the pattern which comes first in patterns is used. May not be used together with overlapping = True.
- Returns:
- Expr
Expression of data type
Listwith inner data typeUInt32.
See also
polars.Expr.str.find_manyReturn the character offsets of many matches.
Examples
>>> df = pl.DataFrame({"values": [b"discontent", b"rhapsody"]}) >>> patterns = [b"winter", b"disco", b"onte", b"discontent"] >>> df.with_columns( ... matches=pl.col("values").bin.find_many(patterns), ... matches_overlapping=pl.col("values").bin.find_many( ... patterns, overlapping=True ... ), ... ) shape: (2, 3) ┌───────────────┬───────────┬─────────────────────┐ │ values ┆ matches ┆ matches_overlapping │ │ --- ┆ --- ┆ --- │ │ binary ┆ list[u32] ┆ list[u32] │ ╞═══════════════╪═══════════╪═════════════════════╡ │ b"discontent" ┆ [0] ┆ [0, 4, 0] │ │ b"rhapsody" ┆ [] ┆ [] │ └───────────────┴───────────┴─────────────────────┘