sed: BRE vs ERE
1
1 5.2 Basic (BRE) and extended (ERE) regular expression
1 =====================================================
1
1 Basic and extended regular expressions are two variations on the syntax
1 of the specified pattern. Basic Regular Expression (BRE) syntax is the
1 default in 'sed' (and similarly in 'grep'). Use the POSIX-specified
1 '-E' option ('-r', '--regexp-extended') to enable Extended Regular
1 Expression (ERE) syntax.
1
1 In GNU 'sed', the only difference between basic and extended regular
1 expressions is in the behavior of a few special characters: '?', '+',
1 parentheses, braces ('{}'), and '|'.
1
1 With basic (BRE) syntax, these characters do not have special meaning
1 unless prefixed backslash ('\'); While with extended (ERE) syntax it is
1 reversed: these characters are special unless they are prefixed with
1 backslash ('\').
1
1 Desired pattern Basic (BRE) Syntax Extended (ERE) Syntax
1
1 --------------------------------------------------------------------------
1 literal '+' (plus $ echo 'a+b=c' > foo $ echo 'a+b=c' > foo
1 sign) $ sed -n '/a+b/p' foo $ sed -E -n '/a\+b/p' foo
1 a+b=c a+b=c
1
1 One or more 'a' $ echo aab > foo $ echo aab > foo
1 characters $ sed -n '/a\+b/p' foo $ sed -E -n '/a+b/p' foo
1 followed by 'b' aab aab
1 (plus sign as
1 special
1 meta-character)
1