{"record":{"id":"aef0a23877baf6e0","repo":"unclecode/crawl4ai","slug":"regex-for-label-won-t-compile-after-fix-e","errorCode":null,"errorMessage":"Regex for '{label}' won’t compile after fix: {e}","messagePattern":"Regex for '(.+?)' won’t compile after fix: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/extraction_strategy.py","lineNumber":2552,"sourceCode":"\n_WB_FIX = re.compile(r\"\\x08\")               # stray back-space   →   word-boundary\n_NEEDS_ESCAPE = re.compile(r\"(?<!\\\\)\\\\(?![\\\\u])\")   # lone backslash\n\ndef _sanitize_schema(schema: Dict[str, str]) -> Dict[str, str]:\n    \"\"\"Fix common JSON-escape goofs coming from LLMs or manual edits.\"\"\"\n    safe = {}\n    for label, pat in schema.items():\n        # 1️⃣ replace accidental control chars (inc. the infamous back-space)\n        pat = _WB_FIX.sub(r\"\\\\b\", pat).translate(_CTRL)\n\n        # 2️⃣ double any single backslash that JSON kept single\n        pat = _NEEDS_ESCAPE.sub(r\"\\\\\\\\\", pat)\n\n        # 3️⃣ quick sanity compile\n        try:\n            re.compile(pat)\n        except re.error as e:\n            raise ValueError(f\"Regex for '{label}' won’t compile after fix: {e}\") from None\n\n        safe[label] = pat\n    return safe\n\n\nclass RegexExtractionStrategy(ExtractionStrategy):\n    \"\"\"\n    A lean strategy that finds e-mails, phones, URLs, dates, money, etc.,\n    using nothing but pre-compiled regular expressions.\n\n    Extraction returns::\n\n        {\n            \"url\":   \"<page-url>\",\n            \"label\": \"<pattern-label>\",\n            \"value\": \"<matched-string>\",\n            \"span\":  [start, end]\n        }","sourceCodeStart":2534,"sourceCodeEnd":2570,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/extraction_strategy.py#L2534-L2570","documentation":"Error \"Regex for '{label}' won’t compile after fix: {e}\" thrown in unclecode/crawl4ai.","triggerScenarios":"Thrown at crawl4ai/extraction_strategy.py:2552 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that the generated regex for the label is syntactically valid; log the failing pattern and correct or escape the offending constructs.","Provide a hand-written override regex for the label instead of relying on the auto-fix path."],"exampleFix":"strategy = RegexExtractionStrategy(custom={\"price\": r\"\\$\\d+(?:\\.\\d{2})?\"})","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}