From: Sebastian Hungerecker Date: 2008-11-17T05:13:52+09:00 Subject: Re: gsub and reg expressions Stuart Clarke wrote: > I can assure you the only way I have been able to get this is by > #{event.description[/Logon Type\:\t2/]} Yes, but that's not an array. That's a method call to String#[]. This has nothing to do with what you're trying to do with gsub. > If I change the expression to #{event.description(/Logon Type\:\t2/)}. > It doesn't work (I dont no why, guess its something to do with library). That doesn't work because you're trying to pass the regexp as an argument to description and I assume that description wasn't defined to take any arguments. > To clarify I want to find Logon Type: 2 in the data set and change it to > Local logon. string.gsub(/regex/, "replacement") will find each part of string that matches /regex/ and then replace those parts (and only those) with "replacement". The rest of the string will not be affected. That's exactly what you want, as far as I can tell, so just remove those brackets. > Hope this helps, I do understand what you are saying with the reg > expressions but, all i can tell you is it works. Well, obviously it doesn't or you wouldn't be here. String#[] let's you get a substring. gsub allows you to replace substrings. []s don't appear anywhere in the call to gsub except as part of the regex. HTH, Sebastian -- NP: Depeche Mode - Lilian Jabber: sepp2k@jabber.org ICQ: 205544826