From: Robert Klemme Date: 2005-09-14T23:36:33+09:00 Subject: Re: Surprising Regexp Behavior Ara.T.Howard wrote: > On Wed, 14 Sep 2005, Robert Klemme wrote: > >> Ah! In that case I'd something like: >> >> html.sub!(/(

)(.*?)(<\/p>)(.*)/) { $1 << $2.strip << $3 } > > it never occured to me that regexes could be made to be context > sensitive in that way - that usage of the block, i think, makes them > recognize more that the regular languages doesn't it? No. The block is just for the replacement. It doesn't change anything for the match. > something like > > string.sub(pat){ $1 =~ /foo/ ? 'bar' : 'baz' } > > though i suppose you can only look backward using this unless the > pattern was made quite general to ensure capture forward.... I don't see how this is look forward or backward. The group actually has to be matched to be able to use it as basis for some kind of conditional replacement. There's no lookahead / lookbehing magic involved - or I cannot see it. :-) Kind regards robert