I am trying to write a function that converts something like "It''s a dog''s life" to "It''s A Dog''s Life". I am doing this with string.gsub(/ \b\w/) {$&.upcase} but this gives me "It''S A Dog''S Life" - how can I tell the regexp to ignore apostrophes when looking for a new word to capitalize? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
item.capitalize ?? --Scott T. On Jul 3, 5:03 pm, raghus <raghu.sriniva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to write a function that converts something like "It''s a > dog''s life" to "It''s A Dog''s Life". I am doing this with string.gsub(/ > \b\w/) {$&.upcase} but this gives me "It''S A Dog''S Life" - how can I > tell the regexp to ignore apostrophes when looking for a new word to > capitalize?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Handlers/UTF8Handler.html#M000289 On Jul 3, 5:03 pm, raghus <raghu.sriniva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to write a function that converts something like "It''s a > dog''s life" to "It''s A Dog''s Life". I am doing this with string.gsub(/ > \b\w/) {$&.upcase} but this gives me "It''S A Dog''S Life" - how can I > tell the regexp to ignore apostrophes when looking for a new word to > capitalize?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
raghus wrote:> I am trying to write a function that converts something like "It''s a > dog''s life" to "It''s A Dog''s Life". I am doing this with string.gsub(/ > \b\w/) {$&.upcase} but this gives me "It''S A Dog''S Life" - how can I > tell the regexp to ignore apostrophes when looking for a new word to > capitalize? > >string.titleize will give you the same result you''re getting. Doesn''t help you at all with this problem, but, just for future reference. But, back to the problem you''re having. This seems to do the trick. string.gsub(/(^|[^\w''])([\w''])/) {$&.upcase} -- http://www.5valleys.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jon - ok that worked. Thank you. Thanks for the titleize tip as well. Scott - mystr.capitalize will capitalize just the first character - so I''d end up with "It''s a dog''s life" rather than "It''s A Dog''s Life" On Jul 3, 4:10 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> raghuswrote: > > I am trying to write a function that converts something like "It''s a > > dog''s life" to "It''s A Dog''s Life". I am doing this with string.gsub(/ > > \b\w/) {$&.upcase} but this gives me "It''S A Dog''S Life" - how can I > > tell the regexp to ignore apostrophes when looking for a new word to > > capitalize? > > string.titleize will give you the same result you''re getting. Doesn''t > help you at all with this problem, but, just for future reference. > > But, back to the problem you''re having. This seems to do the trick. > > string.gsub(/(^|[^\w''])([\w''])/) {$&.upcase} > > --http://www.5valleys.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---