I am using sed. I was using a regex that was correct as far as I could see, but sed did not do anything. Turns out that I was using \s+ which sed can not understand, and when I switched to [ ]+ it worked.

So to sum up, I made a regex which for it to work I had to escape almost everything and remove the \s for whitespace. Seems that there is a mode to avoid all these which is -r So I wanted to ask:

  1. Why isn't -r the default mode for sed? Why did I have to go to so much trouble to escape everything?
  2. man says that there is the option --posix and that "POSIX.2 BREs should be supported" What does this refer to? NFA/DFA mode?
  • As an aside, to match whitespace like perl's \s+ use [[:space:]][:space:]]* in BRE and the same or [[:space:]]+ in ERE.
    – jrm
    Commented Apr 1, 2016 at 3:35

2 Answers 2


Re 1) The answer is the same as for any other tool that was improved over decades. :)

You don't want to break existing scripts by changing default behaviour.

Re 2) That has nothing to do with the matching engine; it's just a question of which set of regular expressions is supported. POSIX BRE means "basic regular expression".


Regarding point 2: gnu sed uses GNU BRE by default. To use POSIX BRE you should specify --posix

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .