title: Capitalize hyphenated names in javascript
body: <p>I need to capitalize names in javascript and so far I've found these methods on SO:</p>
  
  <pre><code>// doesn't capitalize first letter after hyphen -&gt; gives Bjørn-martin
  str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
  
  // capitalizes after hyphen, but also after funny Norwegian characters (æøå) -&gt; gives BjøRn-Martin
  str.replace(/\b[\w']+\b/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
  
  // same as first
  str = str.toLowerCase().replace(/^[\u00C0-\u1FFF\u2C00-\uD7FF\w]|\s[\u00C0-\u1FFF\u2C00-\uD7FF\w]/g, function(letter) {
      return letter.toUpperCase();
  });
  </code></pre>
  
  <p>When trying to capitalize <code>bjørn-martin</code> none of them handles both funny Norwegian characters and hyphen.</p>
  
  <p>I'm not exactly well versed in regex and was wondering if anyone could point me in the right direction so that <code>bjørn-martin</code> is correctly capitalized to <code>Bjørn-Martin</code>.</p>