From: Daniel Finnie Date: 2006-12-09T07:12:18+09:00 Subject: Re: Capitalization Oops, forgot to paste this one in: To get keep words like "of" and "is" lowercase: (basically anything under 3 letters) text.downcase.gsub(/[A-Za-z]{3,}(?!\/)/) {|x| x.capitalize} Daniel Finnie wrote: > Try this: > str.gsub(/[A-Za-z]+/) {|x| x.capitalize} > > If you want the W of W/ uncapitalized: > str.downcase.gsub(/[A-Za-z]+(?!\/)/) {|x| x.capitalize} > > Paul Lutus 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]") >> >> How many special cases? In the worst case, you would have to use a >> dictionary to avoid treating acronyms as a word. You already have two >> rather difficult rules, one having to do with acronyms, another having to >> do with special treatment of the sequence "w/". >> >> What I am saying is this is likely to be more difficult than it seems, >> especially because we only have one example of what might end up being >> thousands of examples of free-form text. >> > >