gnu sed regex grouping not working?

Hello,

from the gnu sed manual, I should be able to do this:

`\(REGEXP\)'
Groups the inner REGEXP as a whole, this is used to:

     * Apply postfix operators, like \`\\\(abcd\\\)*': this will search
       for zero or more whole sequences of \`abcd', while \`abcd*'
       would search for \`abc' followed by zero or more occurrences
       of \`d'.  Note that support for \`\\\(abcd\\\)*' is required by
       POSIX 1003.1-2001, but many non-GNU implementations do not
       support it and hence it is not universally portable.

the version of sed I am using is gnu sed v 4.1.5

The feature mentioned above does not seem to be working; eg,

echo "abc-abc" | sed -r 's/[\(abc\)]/%/g'

gives:

%%%-%%%

If it were treating abc as grouped, I should get:

%-%

I have tried to get this feature to work on several different systems, and never have. I have done a fair amount of googling on this with no answers.

Ultimately what I would like to do is remove text between two strings, eg, <script and </script>, without being greedy. So I would like to be able to do something like:

sed 's/<script[^\(<\/script>\)]*<\/script>//g'

in order to only remove text between a <script string and the next </script> string without removing all the text clear to the last </script> string on the line.

An input on why this does not seem to be working for me would be greatly appreciated.

Allasso

Inside [...] is a list of characters, and it matches a single character.

echo "abc-abc" | sed -r 's/abc/%/g'

thank you for your reply.

Your example works fine for what it does, but the whole point is to be able to use the square brackets so I can use the NOT form -- [^...] -- in order to keep the match from being greedy.

Are you saying that you cannot have a group inside of [...] ?

Exactly. Square brackets match a single character not a string or group.