From: William James Date: 2005-08-07T06:46:08+09:00 Subject: Re: STRING MANIPULATION: Marking syllables basi wrote: > How might one express the following syllabification rules: > > 1. A c(c)v sequence is a syllable if followed by a cv sequence > > pe.so (the dot indicates a syllable break) > pra.da > > 2. A c(c)vc sequence is a syllable if followed by a c > > fal.do > bran.di > > where: > c = consonant > v = vowel > (c) = optional consonant CC = {} CC['v'] = '[aeiou]' CC['c'] = '[^aeiou]' class String # Convert rule like "c(c)vc.c" to a regular expression. def to_syllrule re = "^(" self.scan( /\(?([cv.])(\)?)/ ) { |x| if "." == x[0] re << ")(" else re << CC[ x[0] ] re << "?" if ")" == x[1] end } Regexp.new( re + ".*)" ) end end # Make a list of the rules as regular expressions. rules = %w( c(c)v.cv c(c)vc.c ).inject([]){|a,s| a<< s.to_syllrule } %w( peso prada faldo brandi ).each { |word| rules.each { |re| if word =~ re puts $~.captures.join('.') break end } } ----------------- Output: pe.so pra.da fal.do bran.di