sharkdp/fd · error · anyhow::Error

Note: You can search for literal substrings with…

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

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.

Solutions

  1. Escape metacharacters: `fd '\(foo\)'`.
  2. Use --fixed-strings for literal substring search: `fd --fixed-strings '(foo)'`.
  3. Use --exact for a full-name literal match, or --glob for a glob pattern.

Example fix

# before
fd (foo)

# after (literal substring)
fd --fixed-strings '(foo)'
# or escaped regex
fd '\(foo\)'
Defensive patterns

Strategy: validation

Validate before calling

validate_regex() {
  if printf '%s' "$PATTERN" | grep -Eq '^[A-Za-z0-9._/-]+$'; then
    fd "$PATTERN"           # safe plain pattern
  else
    fd --fixed-strings "$PATTERN"  # literal to avoid regex pitfalls
  fi
}

Prevention

When it happens

Trigger: Running `fd '('`, `fd '*foo'` (unguarded repetition), `fd '[a-'` (unterminated class), `fd '\'` (trailing escape), or any pattern regex::RegexBuilder rejects.

Common situations: Searching for a literal that contains regex metacharacters (*, (, [, +, ?); partial/typo'd regexes; copy-pasting shell globs as if they were regex.

Related errors


AI-assisted analysis of sharkdp/fd@ee20f426dd (2026-08-09). Data as JSON: /api/errors/2d98f3012d3e4fc1. Report an issue: GitHub.

Appendix: 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 ee20f426dd)