From: Robert Klemme Date: 2008-11-17T04:56:43+09:00 Subject: Re: gsub and reg expressions On 16.11.2008 20:00, Stuart Clarke wrote: > I have a field full of data and therefore I am using a regular > expression to extract one part of it - #{event.description[/Logon > Type:\t2/]} > > This works fine. I want to now add in gsub to replace 'Logon Type: 2' > with the string 'Local Logon' - #{event.description.gsub([/Logon > Type:\t2/], 'Local Logon')} As others have pointed out you are mixing up String#[] with String#gsub. Note, that you can do replacements with String#[]= like this: irb(main):001:0> s = "foo bar Logon Type:\t2 baz" => "foo bar Logon Type:\t2 baz" irb(main):002:0> puts s foo bar Logon Type: 2 baz => nil irb(main):003:0> s[/Logon Type:\t2/] = 'Local Logon' => "Local Logon" irb(main):004:0> s => "foo bar Local Logon baz" irb(main):005:0> puts s foo bar Local Logon baz => nil The "classic" version of course would be irb(main):006:0> s = "foo bar Logon Type:\t2 baz" => "foo bar Logon Type:\t2 baz" irb(main):007:0> s.gsub /Logon Type:\t2/, 'Local Logon' => "foo bar Local Logon baz" Note that in your case String#sub might be sufficient. Alternatives are String#sub! and String#gsub! which you can use if you do not want to retain the original string. Cheers robert