manpagez: man pages & more
info sed
Home | html | info | man

File: sed.info,  Node: BRE vs ERE,  Next: BRE syntax,  Prev: Regular Expressions Overview,  Up: sed regular expressions

5.2 Basic (BRE) and extended (ERE) regular expression
=====================================================

Basic and extended regular expressions are two variations on the syntax
of the specified pattern.  Basic Regular Expression (BRE) syntax is the
default in ‘sed’ (and similarly in ‘grep’).  Use the POSIX-specified
‘-E’ option (‘-r’, ‘--regexp-extended’) to enable Extended Regular
Expression (ERE) syntax.

   In GNU ‘sed’, the only difference between basic and extended regular
expressions is in the behavior of a few special characters: ‘?’, ‘+’,
parentheses, braces (‘{}’), and ‘|’.

   With basic (BRE) syntax, these characters do not have special meaning
unless prefixed with a backslash (‘\’); While with extended (ERE) syntax
it is reversed: these characters are special unless they are prefixed
with backslash (‘\’).

Desired pattern      Basic (BRE) Syntax         Extended (ERE) Syntax
                                                
--------------------------------------------------------------------------
literal ‘+’ (plus         $ echo 'a+b=c' > foo       $ echo 'a+b=c' > foo
sign)                     $ sed -n '/a+b/p' foo      $ sed -E -n '/a\+b/p' foo
                          a+b=c                      a+b=c
                                                
One or more ‘a’           $ echo aab > foo           $ echo aab > foo
characters                $ sed -n '/a\+b/p' foo     $ sed -E -n '/a+b/p' foo
followed by ‘b’           aab                        aab
(plus sign as                                   
special
meta-character)

© manpagez.com 2000-2026
Individual documents may contain additional copyright information.