From: "David A. Black" Date: 2009-07-15T22:07:40+09:00 Subject: Re: Search in string with regular expression Hi -- On Wed, 15 Jul 2009, Robert Dober wrote: > On 7/15/09, Harry Kakueki wrote: >>> Maybe >>> str2 = str1.scan( /\bfrog\w*\B/ ).join(" ") >>> that is if you want to match frog at the start of words only (\b) and >>> assure charcters of your choice up to the end of the word? As \w might >>> be a little bit too permissive, in 1.9 you might prefer >>> str2 = str1.scan( /\bfrog[[:alpha:]]*\B/ ).join(" ") >>> and all those nice variations ;) >>> >>> HTH >>> Robert >>> >>> >>> >> Or maybe, :) >> >> str2 = str1.scan( /\bfrog\w*\b/ ).join(" ") > No it was not a typo, I thought that \B was matching at the end of the > word, I did not test with a frog at the end. > I stand corrected \B does not have a special meaning and \b is just a > word boundary. \B is the opposite of \b, i.e., "not at a word boundary". So: >> /\B./.match("word")[0] => "o" David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN)