is it possible to specify non-capturing groups in sed?
if so, how?
See Question&Answers more detail:osis it possible to specify non-capturing groups in sed?
if so, how?
See Question&Answers more detail:osParentheses can be used for grouping alternatives. For example:
sed 's/a(bc|de)f/X/'
says to replace "abcf" or "adef" with "X", but the parentheses also capture. There is not a facility in sed
to do such grouping without also capturing. If you have a complex regex that does both alternative grouping and capturing, you will simply have to be careful in selecting the correct capture group in your replacement.
Perhaps you could say more about what it is you're trying to accomplish (what your need for non-capturing groups is) and why you want to avoid capture groups.
Edit:
There is a type of non-capturing brackets ((?:pattern)
) that are part of Perl-Compatible Regular Expressions (PCRE). They are not supported in sed
(but are when using grep -P
).