{"record":{"id":"2d98f3012d3e4fc1","repo":"sharkdp/fd","slug":"note-you-can-search-for-literal-substrings-wi","errorCode":null,"errorMessage":"{}\n\nNote: You can search for literal substrings with '--fixed-strings' or literal strings with '--exact' options (instead of a regular expression). Alternatively, you can also use the '--glob' option to match on a glob pattern.","messagePattern":"(.+?)\n\nNote: You can search for literal substrings with '--fixed-strings' or literal strings with '--exact' options \\(instead of a regular expression\\)\\. Alternatively, you can also use the '--glob' option to match on a glob pattern\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":547,"sourceCode":"            .any(|pat| pattern_matches_strings_with_leading_dot(pat))\n    {\n        Err(anyhow!(\n            \"The pattern(s) seems to only match files with a leading dot, but hidden files are \\\n            filtered by default. Consider adding -H/--hidden to search hidden files as well \\\n            or adjust your search pattern(s).\"\n        ))\n    } else {\n        Ok(())\n    }\n}\n\nfn build_regex(pattern_regex: String, config: &Config) -> Result<regex::bytes::Regex> {\n    RegexBuilder::new(&pattern_regex)\n        .case_insensitive(!config.case_sensitive)\n        .dot_matches_new_line(true)\n        .build()\n        .map_err(|e| {\n            anyhow!(\n                \"{}\\n\\nNote: You can search for literal substrings with '--fixed-strings' \\\n                 or literal strings with '--exact' options (instead of a regular expression). \\\n                 Alternatively, you can \\\n                 also use the '--glob' option to match on a glob pattern.\",\n                e\n            )\n        })\n}\n","sourceCodeStart":529,"sourceCodeEnd":556,"githubUrl":"https://github.com/sharkdp/fd/blob/ee20f426ddf338ac7ead5c5f00ea49258005caaf/src/main.rs#L529-L556","documentation":"build_regex (main.rs:541) compiles the (possibly transformed) pattern with regex::bytes::RegexBuilder; on a regex_syntax compile failure it wraps the underlying error and appends guidance to switch to --fixed-strings, --exact, or --glob. This catches invalid regex such as unbalanced parentheses, invalid escapes, or unsupported syntax.","triggerScenarios":"Running `fd '('`, `fd '*foo'` (unguarded repetition), `fd '[a-'` (unterminated class), `fd '\\'` (trailing escape), or any pattern regex::RegexBuilder rejects.","commonSituations":"Searching for a literal that contains regex metacharacters (*, (, [, +, ?); partial/typo'd regexes; copy-pasting shell globs as if they were regex.","solutions":["Escape metacharacters: `fd '\\(foo\\)'`.","Use --fixed-strings for literal substring search: `fd --fixed-strings '(foo)'`.","Use --exact for a full-name literal match, or --glob for a glob pattern."],"exampleFix":"# before\nfd (foo)\n\n# after (literal substring)\nfd --fixed-strings '(foo)'\n# or escaped regex\nfd '\\(foo\\)'","handlingStrategy":"validation","validationCode":"validate_regex() {\n  if printf '%s' \"$PATTERN\" | grep -Eq '^[A-Za-z0-9._/-]+$'; then\n    fd \"$PATTERN\"           # safe plain pattern\n  else\n    fd --fixed-strings \"$PATTERN\"  # literal to avoid regex pitfalls\n  fi\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use --fixed-strings for literal substrings containing metacharacters.","Use --glob or --exact for non-regex matching.","Escape regex metacharacters when you truly need a regex."],"tags":["regex","parsing","cli","pattern"],"backgroundTag":null,"analyzedSha":"ee20f426ddf338ac7ead5c5f00ea49258005caaf","analyzedAt":"2026-08-09T08:21:40.573Z","contentChangedAt":"2026-08-09T08:21:40.573Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}