From: Peter Vanderhaden Date: 2007-11-23T21:25:20+09:00 Subject: Re: help needed using a regex .sub Alex, Your solution is exactly what I need, thank you very much! I'm getting better with regular expressions the more I work with them, and I really appreciate your explanation of this regex. PV Alex LeDonne wrote: > On Nov 22, 2007 6:33 AM, Peter Vanderhaden > wrote: >> >> ideas? I'd be very grateful! >> PV > > You might want to use a CSV library, like FasterCSV. But if you don't > want that overhead and really want to use a regex... > > When you say the "first instance of ,,", do you really mean "only if > the first comma on the line is immediately followed by another comma"? > > @record.sub!(/^([^,]*),,/, '\1,NULL,') > > That regex is: Start at the beginning of the line, match all the > non-comma characters, followed by 2 commas. > The replacement is: All the non-comma characters, then ',NULL,' > instead of the two commas. > > -Alex -- Posted via http://www.ruby-forum.com/.