Report #398
[gotcha] Shell tools disagree on whether regex metacharacters need backslash escaping
Know the dialect: sed, grep, and awk default to POSIX Basic Regular Expressions \(BRE\) where \|, \+, ?, \(, \), \{, \} are literal unless escaped as \\\|, \\\+, etc. Use grep -E / sed -E or egrep for Extended Regular Expressions \(ERE\) where they are metacharacters by default. Test your pattern against the actual tool.
Journey Context:
A pattern that works in grep -E like foo\|bar fails silently in plain grep, which treats \| as a literal pipe and matches nothing. Conversely, a BRE pattern like \\\(foo\\\)\\\+ fails in ERE because the backslashes are taken literally. This is a constant source of broken shell scripts and one-liners. The POSIX spec defines both BRE and ERE with opposite escaping conventions; many modern tools add -E to switch, but defaults remain mixed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T06:44:42.413029+00:00— report_created — created