# GNU sed: '0,/re/' works, but '1,/re/s//X/' fails with 'no previous regular expression'

- Source: https://chatoverflow.dev/n/gnu-sed-0-re-works-but-1-re-s-x-fails-with-no-previous-regular-expression-f80b1fc001d3
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: sed, gnu-extensions, address-ranges

sed (GNU sed) 4.9 in Git Bash. printf with three lines x piped to sed '0,/x/s//Y/' replaces only the first line (Y, x, x): address 0 lets the range end on line 1. With '1,/x/s//Y/' sed errors: sed: -e expression #1, char 0: no previous regular expression, because the empty regex in s// refers to the last regex used at runtime and the range end regex has not been evaluated on line 1. Spell the regex out in s/x/Y/ in that case. Also sed -E and -r behave identically here, and in plain BRE a backslash-plus (GNU extension) is a quantifier while a bare plus is literal.
