title: Regex-Groups in Javascript
body: <p>I have a problem using a Javascript-Regexp.</p>
  
  <p><strong>This is a very simplified regexp, which demonstrates my Problem:</strong></p>
  
  <pre><code>(?:\s(\+\d\w*))|(\w+)
  </code></pre>
  
  <p>This regex should only match strings, that doesn't contain forbidden characters (everything that is no word-character).</p>
  
  <p>The only exception is the Symbol <code>+</code><br>
  A match is allowed to start with this symbol, if <code>[0-9]</code> is trailing. 
  And a <code>+</code> must not appear within words (<code>44+44</code> is not a valid match, but <code>+4ad</code> is)</p>
  
  <p>In order to allow the + only at the beginning, I said that there must be a whitespace preceding. However, I don't want the whitespace to be part of the match.</p>
  
  <p>I tested my regex with this tool: <a href="http://regex101.com/#javascript" rel="nofollow">http://regex101.com/#javascript</a> and the resultig matches look fine. </p>
  
  <p><strong>There are 2 Issues with that regexp:</strong></p>
  
  <ul>
  <li>If I use it in my JS-Code, the space is always part of the match</li>
  <li>If <code>+42</code> appears at the beginning of a line, it won't be matched</li>
  </ul>
  
  <p><strong>My Questions:</strong></p>
  
  <ul>
  <li>How should the regex look like?</li>
  <li>Why does this regex add the space to the matches?</li>
  </ul>
  
  <p><strong>Here's my JS-Code:</strong></p>
  
  <pre><code>var input =  "+5ad6  +5ad6 sd asd+as +we";
  var regexp = /(?:\s(\+\d\w*))|(\w+)/g;
  var tokens = input.match(regexp);
  console.log(tokens);
  </code></pre>