Hmbown/CodeWhale · error
tag regex pattern is valid
Error message
tag regex pattern is valid
What it means
Panic compiling the generic HTML tag-stripping pattern `<[^>]+>` in `TAG_RE.get_or_init`. This is the simplest of the scrape literals; the expect can only fire if the literal was edited into something the regex crate rejects (a stray `*`/`+` with nothing to repeat, or an unbalanced bracket class).
Source
Thrown at crates/tui/src/tools/web/scrape.rs:48
fn get_title_re() -> &'static Regex {
TITLE_RE.get_or_init(|| {
Regex::new(r#"<a[^>]*class=\"result__a\"[^>]*href=\"([^\"]+)\"[^>]*>(.*?)</a>"#)
.expect("title regex pattern is valid")
})
}
fn get_snippet_re() -> &'static Regex {
SNIPPET_RE.get_or_init(|| {
Regex::new(
r#"<a[^>]*class=\"result__snippet\"[^>]*>(.*?)</a>|<div[^>]*class=\"result__snippet\"[^>]*>(.*?)</div>"#,
)
.expect("snippet regex pattern is valid")
})
}
fn get_tag_re() -> &'static Regex {
TAG_RE.get_or_init(|| Regex::new(r"<[^>]+>").expect("tag regex pattern is valid"))
}
fn get_bing_result_re() -> &'static Regex {
BING_RESULT_RE.get_or_init(|| {
Regex::new(r#"(?is)<li[^>]*class=\"[^\"]*\bb_algo\b[^\"]*\"[^>]*>(.*?)</li>"#)
.expect("bing result regex pattern is valid")
})
}
fn get_bing_title_re() -> &'static Regex {
BING_TITLE_RE.get_or_init(|| {
Regex::new(r#"(?is)<h2[^>]*>.*?<a[^>]*href=\"([^\"]+)\"[^>]*>(.*?)</a>"#)
.expect("bing title regex pattern is valid")
})
}
fn get_bing_snippet_re() -> &'static Regex {
BING_SNIPPET_RE.get_or_init(|| {View on GitHub (pinned to 0c42157ee5)
Solutions
- Restore or fix the literal — the regex crate's error message in the panic payload names the exact offset.
- Cover the getter in the shared pattern-compile unit test.
- Re-run the scrape tests after the edit.
Example fix
// before
Regex::new(r"<[^>]+>").expect("tag regex pattern is valid")
// after: assert the edited variant still strips a sample tag
#[test]
fn tag_stripper_still_works() {
assert_eq!(get_tag_re().replace_all("a<b>c</b>d", ""), "acd");
} Defensive patterns
Strategy: validation
Validate before calling
#[test]
fn tag_pattern_still_strips() {
assert_eq!(get_tag_re().replace_all("a<b>c</b>d", ""), "acd");
} Try / catch
let text = std::panic::catch_unwind(|| strip_tags(&html))
.unwrap_or_else(|_| html.to_string()); Prevention
- Keep the tag-stripping literal minimal; add tests for any widened variant.
- Include the getter in the shared pattern-compile test.
When it happens
Trigger: An edit to the tag-stripping literal that breaks regex syntax; the first text normalization over scraped HTML after that build panics inside `get_tag_re`.
Common situations: Trying to also strip self-closing or malformed tags (e.g. adding `/?` incorrectly or a broken character class) without re-running tests.
Related errors
- title regex pattern is valid
- snippet regex pattern is valid
- bing result regex pattern is valid
- bing title regex pattern is valid
- bing snippet regex pattern is valid
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/a24b049c792090bd.
Report an issue: GitHub.