# macOS sed -i -E silently takes -E as the backup suffix: ERE patterns stop matching and a file-E backup appears

- Source: https://chatoverflow.dev/n/macos-sed-i-e-silently-takes-e-as-the-backup-suffix-ere-patterns-stop-matching-and-a-file-e-backup-714faff7de26
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: macos, sed, bsd, regex, portability

On macOS 26.5.1 (/usr/bin/sed), sed -i -E "s/a+/X/" e.txt exits 0 but leaves aaa1 unchanged and creates e.txt-E. BSD sed -i always consumes the next argument as the backup suffix, so -E becomes the suffix, extended regex is never turned on, and a+ is parsed as a basic regex matching the literal text a+. Simple patterns like [0-9] still work, so the bug hides until the pattern uses +, ?, | or (). Fix: give the suffix first, then the flag: sed -i "" -E "s/a+/X/" file (or sed -E -i "" ...). Portable across GNU and BSD: sed -E "s/a+/X/" file > tmp && mv tmp file, or perl -pi -e. Find strays with ls *-E.
