{"record":{"id":"6e2582b343282937","repo":"helix-editor/helix","slug":"failed-to-compile-regex","errorCode":null,"errorMessage":"Failed to compile regex","messagePattern":"Failed to compile regex","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"helix-term/src/commands.rs","lineNumber":2637,"sourceCode":"\n        let documents: Vec<_> = editor\n            .documents()\n            .map(|doc| (doc.path().map(ToOwned::to_owned), doc.text().to_owned()))\n            .collect();\n\n        let matcher = match RegexMatcherBuilder::new()\n            .case_smart(config.smart_case)\n            .multi_line(true)\n            .build(query)\n        {\n            Ok(matcher) => {\n                // Clear any \"Failed to compile regex\" errors out of the statusline.\n                editor.clear_status();\n                matcher\n            }\n            Err(err) => {\n                log::info!(\"Failed to compile search pattern in global search: {}\", err);\n                return async { Err(anyhow::anyhow!(\"Failed to compile regex\")) }.boxed();\n            }\n        };\n\n        let dedup_symlinks = config.file_picker_config.deduplicate_links;\n        let absolute_root = search_root\n            .canonicalize()\n            .unwrap_or_else(|_| search_root.clone());\n\n        let injector = injector.clone();\n        async move {\n            let searcher = SearcherBuilder::new()\n                .binary_detection(BinaryDetection::quit(b'\\x00'))\n                .multi_line(true)\n                .build();\n            WalkBuilder::new(search_root)\n                .hidden(config.file_picker_config.hidden)\n                .parents(config.file_picker_config.parents)\n                .ignore(config.file_picker_config.ignore)","sourceCodeStart":2619,"sourceCodeEnd":2655,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-term/src/commands.rs#L2619-L2655","documentation":":global-search builds its matcher with RegexMatcherBuilder (the regex crate, smart-case and multi-line enabled). Queries that are not valid regex — unbalanced parens/brackets, dangling or reversed quantifiers ('*x', 'a{2,1}'), or constructs regex does not support like look-around and backreferences — fail to compile; the picker shows 'Failed to compile regex' and logs the underlying error at info level. On the next keystroke a successful compile clears the statusline error.","triggerScenarios":"Typing '(' alone, '(?=foo)', '*bar', 'a{2,1}', or a literal string containing metacharacters like 'f(x)+' or 'C++(' into the global-search prompt while it dynamically re-runs.","commonSituations":"Searching literal text full of regex metacharacters (code snippets, 'foo(bar)', 'a.b*c'); PCRE habits (look-ahead/behind, backreferences) ported from grep -P or other editors; partially typed patterns in the dynamic query.","solutions":["Escape metacharacters with backslashes: 'foo\\(bar\\)' instead of 'foo(bar)'.","Drop unsupported constructs (look-around, backreferences) — the regex crate cannot compile them; reformulate with classes/alternation.","For pure literal search, escape every one of . * + ? ( ) [ ] { } | ^ $ \\ or start from a metacharacter-free substring."],"exampleFix":"# before: unbalanced group\nfoo(bar\n# after\nfoo\\(bar\\)","handlingStrategy":"validation","validationCode":"// gate the search on the same syntax the matcher uses\nif regex::Regex::new(query).is_ok() {\n    // safe to feed :global-search's dynamic query\n}","typeGuard":"fn is_valid_search_regex(q: &str) -> bool {\n    regex::Regex::new(q).is_ok()\n}","tryCatchPattern":null,"preventionTips":["Escape metacharacters when searching literals; the pattern field is always a regex.","Remember regex (and thus helix search) has no look-around or backreferences."],"tags":["regex","global-search","user-input"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}