title: JS Split multiple delimiters and get delimiters into input value
body: <p>I'm asking you today for a little problem :</p>
  
  <p>I have to live control capitalization/no capitalization with js on an input text field like this:</p>
  
  <ul>
  <li>1st character of the entire string must be uppercase</li>
  <li>1st character of each word (after space or hyphen) is free (lowercase or uppercase allowed)</li>
  <li>All the nother characters must be lowercase</li>
  </ul>
  
  <p><strong>Desired Output: Grand-Father is Nice</strong></p>
  
  <p>I'm not a specialist of JS, i'm using split function, here is my code :</p>
  
  <pre><code>$('#name').on('input change',function() {
  
    var arr1 = $(this).val().split(/[- ]/);
    var result1 = "";
    for (var x=0; x&lt;arr1.length; x++)
      result1+=arr1[x].substring(0,1)+arr1[x].substring(1).toLowerCase()+" ";
    var res1 = result1.substring(0, result1.length-1);
  
    var _txt = res1.charAt(0).toUpperCase() + res1.slice(1);
    $('#name').val(_txt);
  
  });
  </code></pre>
  
  <p>The script works but I would like to output the real delimiter found in string, even if it's a space " " or hyphen "-". Actually i can show only space. How can i solve it ?</p>
  
  <p><strong>Actual output: Grand Father is Nice</strong></p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thank you!</p>