{"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":3011,"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":2993,"sourceCodeEnd":3029,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/expr/string.py#L2993-L3029","documentation":"Expr.str.extract_many rejects overlapping=True combined with leftmost=True: the leftmost-first strategy resolves exactly one match per position and cannot simultaneously emit overlapping matches, so the flag combination is contradictory and raises ValueError before any matching runs.","triggerScenarios":".str.extract_many(pl.col('pats'), overlapping=True, leftmost=True); copy-pasting flag combinations from find_many or Aho-Corasick examples; incrementally adding leftmost for deterministic longest-match output while keeping overlapping from an earlier iteration.","commonSituations":"Tuning multi-pattern matching semantics to mimic Python's re (leftmost-longest); flag dicts forwarded via **kwargs where both keys end up True.","solutions":["Drop leftmost: .str.extract_many(pats, overlapping=True)","Or drop overlapping: .str.extract_many(pats, leftmost=True)","If you need both behaviors, run two extractions and merge/deduplicate the result lists yourself","Validate forwarded kwargs so the two flags are never both truthy"],"exampleFix":"# before\npl.col('s').str.extract_many(pl.col('pats'), overlapping=True, leftmost=True)\n\n# after\npl.col('s').str.extract_many(pl.col('pats'), overlapping=True)\n# or\npl.col('s').str.extract_many(pl.col('pats'), leftmost=True)","handlingStrategy":"validation","validationCode":"if overlapping and leftmost:\n    raise ValueError('choose either overlapping or leftmost, not both')\nexpr = pl.col('s').str.extract_many(pl.col('pats'), overlapping=overlapping, leftmost=leftmost)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document which matching semantics each call site needs and set only that flag","Do not forward blanket **kwargs into *_many methods","Write a unit test per flag combination you rely on"],"tags":["polars","regex","valueerror","extract","flags"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}