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( '(?<dashes>^-*)(?<after>.*)' ) #=> /(?<dashes>^-*)(?<after>.*)/ s #=> "-------abcde-gh----" m=re.match s #=> #<MatchData:0x2c51b7c> m[:dashes] #=> "-------" m[:after] #=> "abcde-gh----" ... nice naming feature, but overkill for this case. ymmv. kind regards -botp