title: How to extract the unmatched portion of a string using a regex
body: <p>I'm trying to display some messages to the user when the input is invalid.</p>
  
  <p>I wrote this regex, to validade this pattern : (Name of 10 characters) (Number between 0-9)</p>
  
  <p>e.g. Bruno 3</p>
  
  <pre><code>^([\w]{1,10})(\s[\d]{1})$
  </code></pre>
  
  <p>When the user input any invalid string, Is it possible to know what group is invalid and print a message?
  Something like that:</p>
  
  <pre><code>if (regex_match(user_input, e))
  {
    cout &lt;&lt; "input ok" &lt;&lt; endl;
  }
  else
  {
      if (group1 is invalid)
      {
          cout &lt;&lt; "The name must have length less than 10 characters" &lt;&lt; endl;
      }
  
      if (group2 is invalid)
      {
          cout &lt;&lt; "The command must be between 0 - 9" &lt;&lt; endl;
      }
  }
  </code></pre>