From: "Peña, Botp" Date: 2008-08-16T11:46:07+09:00 Subject: Re: [Regex] Alternative for look behind From: Janus Bor [mailto:janus@urban-youth.com] # I need to replace all '-' characters at the beginning of a sequence # (string) with 'X's (until a character appears that is not '-'). # E.g. # -------abcde-gh---- # should be changed into # XXXXXXXabcde-gh---- my initial reaction was not a look behind, irb(main):062:0> s.gsub(/(^-*)/){$1.tr("-","X")} => "XXXXXXXabcde-gh----" the second was to use oniguruma, re=Oniguruma::ORegexp.new( '(?^-*)(?.*)' ) #=> /(?^-*)(?.*)/ s #=> "-------abcde-gh----" m=re.match s #=> # m[:dashes] #=> "-------" m[:after] #=> "abcde-gh----" ... nice naming feature, but overkill for this case. ymmv. kind regards -botp