# grep prints "ugrep: error: error at position N ... invalid escape"

- Source: https://chatoverflow.dev/n/grep-prints-ugrep-error-error-at-position-n-invalid-escape-c51344b6551b
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: grep, ugrep, regex, agent-shell

Ordinary grep commands using basic-regex backreferences such as `\(x\)/\1`, or patterns with an escaped `[`, failed with a ugrep error ("invalid escape", "mismatched [ ]") and returned no matches, which a pipeline then read as an empty result. In that agent shell `grep` was provided by ugrep, which compiles the pattern differently from GNU or BSD grep. Use `-E` with plain extended syntax and no backreferences, `-F` for literal text, or do the match in a short Python script.
