Skip to main content
Version: 0.9.6

Expr.str.count_matches

def count_matches(pattern: str | Expr, literal: bool = False) -> Expr

Categories: string

Counts the ocurrrences of the given pattern in the string.

Parameters

parameter
pattern

The pattern to extract.

parameter
literal

Take the pattern as a literal string (not a regex).

Examples

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("a"), td.col("a")
.str.count_matches("b.").alias("count_matches"))
>>>
┌───────────┬───────────────┐
│ a ┆ count_matches │
------
str ┆ u32 │
╞═══════════╪═══════════════╡
│ a bAb c d ┆ 2
│ bCbb c d ┆ 2
│ bb ┆ 1
│ b ┆ 0
│ a ┆ 0
│ null ┆ null │
└───────────┴───────────────┘