Re: sed bug grouping
Davide Brini <[email protected]>
| Newsgroups | gmane.comp.gnu.utils.bugs |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 25 May 2014 10:17:24 -0400, William Roeder <[email protected]> wrote: > Html/pdf docs () for 1) for postfix operators, like \(abcd\)* and 2) > back references. The problem is when using *both*. > echo 12345ab|sed -r "s/^([^a]{3})*(a)/<\1><\2>/" > 12345ab > does not match as expected > > echo 123456ab|sed -r "s/^([^a]{3})*(a)/<\1><\2>/" > <456><a>b > expected <123456><a>b > > adding a second grouping is a work around > echo 123456ab|sed -r "s/^(([^a]{3})*)(a)/<\1><\3>/" > <123456><a>b > >echo 123456a123ab|sed -r "s/(([^a]{3})*)(a)/<\1><\3>/g" > <123456><a><123><a>b This is expected behavior. If you want the whole "zero or more [^a]{3}" match you must capture it, as you do in the second example. (x)* does NOT give you zero or more a's in the backreference, (x*) does. -- D.