From: Jeremy Bopp Date: 2010-11-10T02:10:42+09:00 Subject: Re: bug in ruby 1.9.2-p0 gsub? On 11/9/2010 11:03 AM, Sd He wrote: > Why does the following only replace the first instance of the pattern? > > '|\\ |\\ |'.gsub(/\|\\ \|/, "||") The pattern is matching pairs of | characters with content in between. Once it matches the first instance, there is only a single | character remaining in the original string. The replacement text is not taken into consideration. Try the following modification instead. It uses a lookahead assertion to avoid consuming the trailing | character in each sequence: '|\\ |\\ |'.gsub(/\|\\ (?=\|)/, "|") Since the search does not consume the trailing | character, the replacement string is only a single | character rather than a double. -Jeremy