9fans archive / 2008 / 10 / 367 /    prev next

From: "Rob Pike" <robpike@gma...>
Subject: Re: [9fans] non greedy regular expressions
Date: Sun, 26 Oct 2008 14:23:59 -0700

The ability to put \1 in the right hand side of a substitution was
done by jason@
at the Uni of Sydney, but after the Sam papers were published.  It was a welcome
feature that added special functionality to the 's' command within
Sam. (Ed(1) had
the feature, within its limited regexps, long before, of course.)

-rob


On Fri, Oct 24, 2008 at 12:56 PM, Rudolf Sykora <rudolf.sykora@gma...> wrote:
> 2008/10/24 Charles Forsyth <forsyth@ter...>:
>>>If I try sth. like
>>>/( b(.)b)/a/\1\2/
>>>on
>>>bla blb 56
>>>I get
>>>bla blb\1\2 56
>>>which is not quite what I want... How then? (I'd like to get 'bla blblblb 56')
>>
>> echo bla blb 56 | sed 's/( b(.)b)/&\1\2/'
>> bla blb blbl 56
>>
>> similarly use `s' not `a' in sam.
>
>
> Yes. But my question was more subtle. I know it can be done with the
> 's' command in sam now. But I asked sth. different. The documentation
> (paper about sam) says 's' is redundant. But it seems (only seems
> since documentation says nothing), that submatches only work with the
> 's' command. If this is true 's' is not redundant, since if it weren't
> there you would not have any chance to use \1, \2, etc.
> That was the reason I wanted to have my example rewritten WITHOUT the
> 's' command...
>
> But anyway thanks!
> Ruda
>
>