From: 7stud -- Date: 2007-11-24T04:04:46+09:00 Subject: Re: help needed using a regex .sub Peter Vanderhaden wrote: > 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 On my system, this solution is 80% faster, and if your strings get longer it will be faster still: str = 'PWCLLP-243-00000002,,Images\1\pwcllp_243_00000002.tif,,,,' first_comma_pos = str.index(',') next_char_pos = first_comma_pos + 1 if str[next_char_pos] == ?, str.insert(next_char_pos, 'NULL') end puts str -- Posted via http://www.ruby-forum.com/.