polars.Series.str.contains#

Series.str.contains(pattern: str, literal: bool = False) Series[source]#

Check if strings in Series contain a substring that matches a regex.

Parameters:
pattern

A valid regex pattern.

literal

Treat pattern as a literal string.

Returns:
Boolean mask

Examples

>>> s = pl.Series(["Crab", "cat and dog", "rab$bit", None])
>>> s.str.contains("cat|bit")
shape: (4,)
Series: '' [bool]
[
    false
    true
    true
    null
]
>>> s.str.contains("rab$", literal=True)
shape: (4,)
Series: '' [bool]
[
    false
    false
    true
    null
]