in reply to Replacing consecutive tokens in 1 pass

You need to use a non-greedy multiplier:

s{ \|9 [0-6]+? # Here's the magic part \| } { |X| }xg

----
Reinvent a rounder wheel.

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Replacing consecutive tokens in 1 pass
by tall_man (Parson) on Feb 21, 2003 at 17:57 UTC
    That won't work. What he needs is a positive look-ahead assertion, like this:
    use strict; $_ = "|90|93|foo|bar|91|92|95|96|906|"; s{ \|9 [0-6]+ (?=\|) } {|X}xg; print $_,"\n";
    You also can't use 'x' mode to ignore whitespace in the replacement part. I also fixed that.