{"record":{"id":"7aa5d0e5b79d98dd","repo":"Hmbown/CodeWhale","slug":"bing-result-regex-pattern-is-valid","errorCode":null,"errorMessage":"bing result regex pattern is valid","messagePattern":"bing result regex pattern is valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/web/scrape.rs","lineNumber":54,"sourceCode":"}\n\nfn get_snippet_re() -> &'static Regex {\n    SNIPPET_RE.get_or_init(|| {\n        Regex::new(\n            r#\"<a[^>]*class=\\\"result__snippet\\\"[^>]*>(.*?)</a>|<div[^>]*class=\\\"result__snippet\\\"[^>]*>(.*?)</div>\"#,\n        )\n        .expect(\"snippet regex pattern is valid\")\n    })\n}\n\nfn get_tag_re() -> &'static Regex {\n    TAG_RE.get_or_init(|| Regex::new(r\"<[^>]+>\").expect(\"tag regex pattern is valid\"))\n}\n\nfn get_bing_result_re() -> &'static Regex {\n    BING_RESULT_RE.get_or_init(|| {\n        Regex::new(r#\"(?is)<li[^>]*class=\\\"[^\\\"]*\\bb_algo\\b[^\\\"]*\\\"[^>]*>(.*?)</li>\"#)\n            .expect(\"bing result regex pattern is valid\")\n    })\n}\n\nfn get_bing_title_re() -> &'static Regex {\n    BING_TITLE_RE.get_or_init(|| {\n        Regex::new(r#\"(?is)<h2[^>]*>.*?<a[^>]*href=\\\"([^\\\"]+)\\\"[^>]*>(.*?)</a>\"#)\n            .expect(\"bing title regex pattern is valid\")\n    })\n}\n\nfn get_bing_snippet_re() -> &'static Regex {\n    BING_SNIPPET_RE.get_or_init(|| {\n        Regex::new(r#\"(?is)<div[^>]*class=\\\"[^\\\"]*\\bb_caption\\b[^\\\"]*\\\"[^>]*>.*?<p[^>]*>(.*?)</p>\"#)\n            .expect(\"bing snippet regex pattern is valid\")\n    })\n}\n\n/// Parse DuckDuckGo HTML SERP results. Known spam-domain hits are omitted.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/web/scrape.rs#L36-L72","documentation":"Panic compiling the Bing result-list pattern `(?is)<li[^>]*class=\"[^\"]*\\bb_algo\\b[^\"]*\"[^>]*>(.*?)</li>` in `BING_RESULT_RE.get_or_init`. The literal mixes an inline case-insensitive/dot-matches-newline flag group `(?is)` with a `\\b` word boundary inside a raw string; an edit that unbalances the flag group or drops the escaped `\\b` to a bare `b` changes semantics, and one that breaks escaping/grouping makes `Regex::new` return `Err`, tripping the expect.","triggerScenarios":"Editing the Bing selector for a markup change and breaking group balance or the `\\b` escapes inside the raw-string literal; the first `parse_bing_results` call after that build panics.","commonSituations":"Adapting to Bing SERP HTML changes; porting a pattern from a dialect where `\\b` or inline flags behave differently; forgetting that inside `r#\"...\"#` a literal `\"` still needs `\\\"` for the regex, not for Rust.","solutions":["Fix the literal; double-check `\\b` (word boundary) is kept double-backslashed in intent and that every `(` has its `)`.","Validate the pattern standalone: `regex::Regex::new(...).is_ok()` in a scratch test.","Include the getter in the shared compile-all-patterns unit test."],"exampleFix":"// before\nRegex::new(r#\"(?is)<li[^>]*class=\\\"[^\\\"]*\\bb_algo\\b[^\\\"]*\\\"[^>]*>(.*?)</li>\"#)\n    .expect(\"bing result regex pattern is valid\")\n\n// after: catch a broken edit in CI before it ships\n#[test]\nfn bing_patterns_compile() {\n    assert!(get_bing_result_re().is_match(\n        r#\"<li class=\"b_algo\"\"><h2>x</h2></li>\"#,\n    ));\n}","handlingStrategy":"validation","validationCode":"#[test]\nfn bing_result_pattern_compiles_and_matches() {\n    assert!(get_bing_result_re().is_match(\n        r#\"<li class=\"b_algo\"><h2>x</h2></li>\"#,\n    ));\n}","typeGuard":null,"tryCatchPattern":"let results = std::panic::catch_unwind(|| parse_bing_results(&html, max_results))\n    .unwrap_or_default();","preventionTips":["Inside raw-string regex literals, keep attribute quotes as `\\\"` deliberately; do not 'simplify' them.","Pin Bing/DDG pattern edits with a match test against a small HTML fixture."],"tags":["rust","regex","bing","html-scraping","panic","expect"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}