Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

sed extended regexp and subexpressions

Cathy344
Occasional Visitor

sed extended regexp and subexpressions

Has anybody here ever managed to use sed with extended regexp's turned on (-r|--regexp-extended) and been able to use subexpressions \( \) and backreferences \1, \2, \n in substitution commands?

Because extended regexp's use parentheses for grouping expressions, in order to match a literal paren in the pattern space, you have to escape the paren, but esccaped parens are what subexpressions in substitution commands use to denote patterns which may be referenced by backreferences. So, how do you denote subexpressions for backreferences with extended regexp turned on?

--
Cathy344
1 REPLY
Mike Stroyan
Honored Contributor

Re: sed extended regexp and subexpressions

The last paragraph in the DESCRIPTION section of "man 7 regex" states that the \( \) and
\1 \2 subexpression notations are specific
to the 'basic' regular expressions. There
is no equivalent for extended regular
expressions.