bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed bug grouping


From: Davide Brini
Subject: Re: sed bug grouping
Date: Sun, 25 May 2014 22:51:48 +0200

On Sun, 25 May 2014 10:17:24 -0400, William Roeder <address@hidden>
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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]