sharkdp/fd · error · anyhow::Error

{} Note: You can search for literal substrings with '--fixe

Error message

{}

Note: 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.

What it means

Thrown by build_regex in src/main.rs:547 when RegexBuilder::new(...).build() fails to compile the assembled pattern. fd wraps the underlying regex crate error and appends a hint pointing to --fixed-strings, --exact, or --glob for users who did not intend a regex. This is the catch-all for syntactically invalid regex input.

Source

Thrown at src/main.rs:547

            .any(|pat| pattern_matches_strings_with_leading_dot(pat))
    {
        Err(anyhow!(
            "The pattern(s) seems to only match files with a leading dot, but hidden files are \
            filtered by default. Consider adding -H/--hidden to search hidden files as well \
            or adjust your search pattern(s)."
        ))
    } else {
        Ok(())
    }
}

fn build_regex(pattern_regex: String, config: &Config) -> Result<regex::bytes::Regex> {
    RegexBuilder::new(&pattern_regex)
        .case_insensitive(!config.case_sensitive)
        .dot_matches_new_line(true)
        .build()
        .map_err(|e| {
            anyhow!(
                "{}\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.",
                e
            )
        })
}

View on GitHub (pinned to 41532d114e)

Solutions

  1. If you meant a glob, use --glob: 'fd --glob "*.rs"'.
  2. If you meant a literal substring, use --fixed-strings: 'fd --fixed-strings "$10"'.
  3. If you want a full-name exact match, use --exact: 'fd --exact foo.txt'.
  4. Otherwise, fix the regex syntax (balance brackets/parens, escape metacharacters) and retry.

Example fix

// before
fd '*.rs'

// after
fd --glob '*.rs'
Defensive patterns

Strategy: validation

Validate before calling

# pick the right matching mode before calling fd
if printf '%s' "$PAT" | grep -Eq '[*?]'; then
  fd --glob "$PAT" "$@"          # glob input
elif [ -n "$LITERAL" ]; then
  fd --fixed-strings "$PAT" "$@" # literal substring
else
  # pre-validate the regex compiles
  if ! printf '%s' "$PAT" | grep -Eq '\\|\(|\)|\[|\{|\*|\+'; then :; fi
  fd "$PAT" "$@"
fi

Type guard

use regex::{RegexBuilder, bytes::Regex};
fn regex_compiles(pat: &str) -> bool {
    RegexBuilder::new(pat).build().is_ok()
}

Prevention

When it happens

Trigger: Running 'fd [unclosed', 'fd *' (unguarded quantifier), 'fd (a|b', or any pattern the regex crate rejects.

Common situations: Typing a glob ('*.rs') expecting shell globbing; unbalanced brackets/parens; stray backslashes; legacy POSIX regex syntax.

Related errors


AI-assisted analysis of sharkdp/fd@41532d114e (2026-08-06). Data as JSON: /data/errors/2d98f3012d3e4fc1.json. Report an issue: GitHub.