From: "David A. Black" Date: 2005-04-28T11:10:53+09:00 Subject: Re: Scanning a String Hi -- On Thu, 28 Apr 2005, Nicholas Seckar wrote: > On 4/27/05, basi wrote: >> Hello, >> How do I scan a string for a pattern and process it when found? For >> example: >> >> for all occurrences of two vowel letters in succession, insert the >> apostrophe between the vowels. > > some_string.gsub(/([aeiou])([aeiou])/) {|match| $1 + "'" + $2} (You don't really need the block arg (match) :-) Just to add a possible variant: depending how you want to handle three or more vowels in a row, you might want to do: pious".gsub(/([aeiou])(?=[aeiou])/) { "#{$1}'#{$2}" } which will result in: pi'o'us (I thought there was a [[:vowel:]] POSIX character class but apparently not.) David -- David A. Black dblack@wobblini.net