Post History
What do you want to find though? Is the + a quantifier, meaning you are looking for one or more b? Or are you looking for the literal string b+? If the latter, you don't need to escape at all and i...
Answer
#1: Initial revision
What do you want to find though? Is the `+` a quantifier, meaning you are looking for one or more `b`? Or are you looking for the literal string `b+`? If the latter, you don't need to escape at all and if the former, you can just use `sed -E 's/b+/X/'` directly. The reason you need to escape in single quoted strings has nothing to do with the shell and is all about the regular expression language used. [By default](https://www.gnu.org/software/sed/manual/html_node/BRE-vs-ERE.html), `sed` will use BRE (basic regular expressions) and in this regex flavor, `+` is just a literal `+` sign and you need `\+` for "one or more". However, most `sed` implementations, including GNU `sed`, the default on Linux, have an `-E` switch which enables ERE (extended regular expressions) and in this regex flavor, `+` has a special meaning and so only needs to be escaped as `\+` if you want to search for a literal `+`. All this to say that there won't be a magic bullet here because sometimes you will want to escape special characters and other times you'll want to use them in all their special glory. So if you're coming from more powerful regex flavors such as ERE or PCRE (versions of which are the default in perl and python and many other places), you can just use `-E` to make the regex behave as you likely expect it to: ``` $ echo "foo" | sed -E 's/o+/A/' fa $ echo abcdefg | sed -E 's/[b-f]+/A/' aAg $ echo foooooo | sed -E 's/o{3,5}/A/' fAo ```