From: Jason Vogel Date: 2006-12-10T16:40:06+09:00 Subject: Re: Capitalization William, This is exactly what I'm looking for. I don't understand it, but it's what I'm looking for. Would you mind explaining what your code does? Thanks, Jason On Dec 8, 8:23 pm, "William James" wrote: > Jason Vogel wrote: > > Disclaimer : Ruby Nuby and I don't know RegEx basically at all. I know > > RegEx is the answer, just don't know where to start. > > > Current Source: > > str.split(' ').each {|w| w.capitalize!}.join(' ') > > > Text: > > ADDITIONAL SPA (ONLY AVAILABLE W/PURCHASE OF POOL OR SPA) > > SELLER HEAT/AC/DUCTWORK > > > Result: > > Additional Spa (only Available W/purchase Of Pool Or Spa) > > Seller Heat/ac/ductwork > > > Desired: > > Additional Spa (Only Available w/Purchase of Pool or Spa) > > Seller Heat/AC/Ductwork > > > Isssus: > > - Need to capitalize after a "/' > > - Need specific word case handling (e.g. "Ac" => "AC","or" => "or", > > "w/[a]" => "w/[A]") > > > Thanks, > > Jasonspecials = %w( of or w AC ). > inject({}){|h,s| h.update({s.downcase,s}) } > > puts DATA.read.downcase.split( /([^a-z]+)/ ).map{|s| > specials[s] or s.capitalize }.join > > __END__ > ADDITIONAL SPA (ONLY AVAILABLE W/PURCHASE OF POOL OR SPA) > SELLER HEAT/AC/DUCTWORK > > --- output ----- > Additional Spa (Only Available w/Purchase of Pool or Spa) > Seller Heat/AC/Ductwork