Patrick R. Michaud: > Ruud H.G. van Tol: >>>>>> 's/$/foo/' becomes 's/<after .*>/foo/' >>>>> >>>>> Uh, no, because <after> is still a zero width assertion. :-) >>>> >>>> That's why I chose it. It is not at the end-of-string? >>> >>> Because ".*" matches "", /<after .*>/ would be true at >>> every position in the string, including the beginning, >>> and this is where "foo" would be substituted. >> >> I expected greediness, also because <after .*?> could behave >> non-greedy. ... >> But why does <after .*> behave non-greedy? > > I think you may be misreading what <after .*> does -- it's a > lookbehind assertion.
No, I was no longer misreading it, I was questioning its rationale. I wondered what would be lost if the construct would behave more like 's/(.*)/$1foo/'. Sorry for not making that more explicit. I was still getting rid of the '$'. And monitoring the outbreak of sober.u. > The greediness of the .* subpattern in <after .*> doesn't affect > things at all -- <after .*> is still a zero-width assertion. There is a zero-width 'slot' before (and after) each character in the pattern string. As a zero-width assertion, '<after .*>' has no sense, no 'self', since it can't move the match position to another slot. In '<after ab*>', the 'b*' means nothing. In '<after ab+>', the '+' means nothing. In '<after .*a>', the '.*' means nothing. Unless the meaning of '<after .*a>' would be changed to: try the last 'a' first. -- Grtz, Ruud