From: Stefano Crocco Date: 2009-11-22T00:12:04+09:00 Subject: Re: Removing optional white space On Saturday 21 November 2009, Philip Rhoades wrote: > |People, > | > |I want to change: > | > | To: phil > | > |or: > | > | To:phil > | > |into: > | > | phil > | > |- I can do this with two gsubs - is it possible to do it with one? > | > |Thanks, > | > |Phil. > | This should work. The regexp searches for the string To: followed by any number of whitespaces (including 0) followed by a letter. Since a positive look-haead is used for the letter, it isn't replaced. s1 = "To: phil" s2 = "To:phil" reg = /To:\s*(?=\w)/ s1.gsub(reg,'') s2.gsub(reg,'') If you are sure that there can be at most one whitespace after the :, you can replace \s* (which matches any number of whitespaces) with \s?, which matches zero or one whitespaces. I hope this helps Stefano