Linux – Why isn’t sed using the extended regex mode by default

linuxregular expressionsed

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?

Best Answer

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".

Related Question