-3

I am trying to capitalize words with a format like this:

america [asia] europe

and I want to make it look like this:

America [Asia] Europe

What regex should I put in the .split option?

kobaltz
  • 6,980
  • 1
  • 35
  • 52
  • Your data doesn't make sense. What is `america [asia] europe`? An array, a string? – victorkt Mar 11 '15 at 18:41
  • Obligatory joke: You have a problem. You decide to use a regex. Now you have two problems. Seriously: is that the only form of the string, or can the brackets move around, like "[america] asia europe", "america [asia] europe", or "america asia [europe]"? I'd try stuff out in an online regex tester. – railsdog Mar 11 '15 at 18:47

1 Answers1

1

If your string is america [asia] europe, then there is no need for regex. Instead use, the builtin helpers methods within Rails. The method titleize is meant for this kind of thing.

➜  test_app git:(master) ✗ rails c
Loading development environment (Rails 4.2.0)

test_app :001 > t = 'america [asia] europe'
 => "america [asia] europe" 

test_app :002 > t.titleize
 => "America [Asia] Europe" 
kobaltz
  • 6,980
  • 1
  • 35
  • 52