{"record":{"id":"87e82b37e2740884","repo":"pola-rs/polars","slug":"can-not-match-overlapping-patterns-when-leftmost","errorCode":null,"errorMessage":"can not match overlapping patterns when leftmost == True","messagePattern":"can not match overlapping patterns when leftmost == True","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/string.py","lineNumber":2960,"sourceCode":"        ... )\n        >>> df.select(pl.col(\"values\").str.extract_many(\"patterns\"))\n        shape: (2, 1)\n        ┌─────────────────┐\n        │ values          │\n        │ ---             │\n        │ list[str]       │\n        ╞═════════════════╡\n        │ [\"disco\"]       │\n        │ [\"rhap\", \"ody\"] │\n        └─────────────────┘\n\n        See Also\n        --------\n        replace_many\n        \"\"\"\n        if overlapping and leftmost:\n            msg = \"can not match overlapping patterns when leftmost == True\"\n            raise ValueError(msg)\n        patterns_pyexpr = parse_into_expression(patterns, str_as_lit=False)\n        return wrap_expr(\n            self._pyexpr.str_extract_many(\n                patterns_pyexpr, ascii_case_insensitive, overlapping, leftmost\n            )\n        )\n\n    @unstable()\n    def find_many(\n        self,\n        patterns: IntoExpr,\n        *,\n        ascii_case_insensitive: bool = False,\n        overlapping: bool = False,\n        leftmost: bool = False,\n    ) -> Expr:\n        \"\"\"\n        Use the Aho-Corasick algorithm to find many matches.","sourceCodeStart":2942,"sourceCodeEnd":2978,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/string.py#L2942-L2978","documentation":"Expr.str.extract_many() can either scan for all overlapping matches or return the leftmost non-overlapping match per pattern, but not both: `overlapping=True` and `leftmost=True` are contradictory modes. polars raises ValueError up front when both are set.","triggerScenarios":"Calling `pl.col('x').str.extract_many(patterns, overlapping=True, leftmost=True)`.","commonSituations":"Copy-pasting keyword arguments from docs of both modes; wanting exhaustive matches while also assuming leftmost ordering semantics.","solutions":["Set `leftmost=False` (default) to keep overlapping matching","Or set `overlapping=False` if you need leftmost match semantics","Decide which mode you need: exhaustive overlap vs leftmost-per-pattern"],"exampleFix":"// before\npl.col('x').str.extract_many(['ab', 'bc'], overlapping=True, leftmost=True)\n// after\npl.col('x').str.extract_many(['ab', 'bc'], overlapping=True)","handlingStrategy":"validation","validationCode":"if overlapping and leftmost:\n    raise ValueError('overlapping and leftmost are mutually exclusive')","typeGuard":null,"tryCatchPattern":"try:\n    expr = pl.col('x').str.extract_many(pats, overlapping=True, leftmost=True)\nexcept ValueError:\n    expr = pl.col('x').str.extract_many(pats, overlapping=True)","preventionTips":["Choose one match mode per call site and document it","Centralize extract_many/find_many calls in a helper that owns the flags"],"tags":["polars","value-error","conflicting-options","python"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}