tabsdata.tableframe.expr.string.ExprStringNameSpace.count_matches#
- ExprStringNameSpace.count_matches(pattern: str | Expr, *, literal: bool = False) Expr [source]#
Counts the ocurrrences of the given pattern in the string.
- Parameters:
pattern – The pattern to extract.
literal – Take the pattern as a literal string (not a regex).
Example:
>>> 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 │ └───────────┴───────────────┘