title: Regex how to get a full match of nth word (without using non-capturing groups)
body: <p>I am trying to use Regex to return the nth word in a string. This would be simple enough using other answers to similar questions; however, I do not have access to any of the code. I can only access a regex input field and the server only returns the 'full match' and cannot be made to return any captured groups such as 'group 1'</p>
  
  <p>EDIT:
  From the developers explaining the version of regex used:</p>
  
  <blockquote>
    <p>"...its javascript regex so should mostly be compatible with perl i
    believe but not as advanced, its fairly low level so wasn't really
    intended for use by end users when originally implemented - i added
    the dropdown with the intention of having some presets going
    forwards."</p>
  </blockquote>
  
  <p>/EDIT</p>
  
  <p>Sample String:</p>
  
  <blockquote>
    <p>One Two Three Four Five</p>
  </blockquote>
  
  <p>Attempted solution (which is meant to get just the 2nd word):</p>
  
  <pre><code>^(?:\w+ ){1}(\S+)$
  </code></pre>
  
  <p>The result is:</p>
  
  <blockquote>
    <p>One Two</p>
  </blockquote>
  
  <p>I have also tried other variations of the regex:</p>
  
  <pre><code>(?:\w+ ){1}(\S+)$
  ^(?:\w+ ){1}(\S+)
  </code></pre>
  
  <p>But these just return the entire string.</p>
  
  <p>I have tried replicating the behaviour that I see using <a href="https://regex101.com/" rel="nofollow noreferrer">regex101</a> but the results seem to be different, particularly when changing around the <code>^</code> and <code>$</code>.</p>
  
  <p>For example, I get the same output on <a href="https://regex101.com/" rel="nofollow noreferrer">regex101</a> if I use the altered regex:</p>
  
  <pre><code>^(?:\w+ ){1}(\S+)
  </code></pre>
  
  <p>In any case, none of the comparing has helped me actually achieve my stated aim.</p>
  
  <p>I am hoping that I have just missed something basic!</p>
  
  <p>===EDIT===</p>
  
  <p>Thanks to all of you who have contributed thus far, however, I am still running into issues. I am afraid that I do not know the language or restrictions on the regex other than what I can ascertain through trial and error, therefore here is a list of attempts and results all of which are trying to return "Two" from a sample of:</p>
  
  <blockquote>
    <p>One Two Three Four Five</p>
  </blockquote>
  
  <pre><code>\w+(?=( \w+){1}$)
  </code></pre>
  
  <p>returns all words</p>
  
  <pre><code>^(\w+ ){1}\K(\w+)
  </code></pre>
  
  <p>returns no words atall (so I assume that <code>\K</code> does not work)</p>
  
  <pre><code>(\w+? ){1}\K(\w+?)(?= )
  </code></pre>
  
  <p>returns no words at all</p>
  
  <pre><code>\w+(?=\s\w+\s\w+\s\w+$)
  </code></pre>
  
  <p>returns all words</p>
  
  <pre><code>^(?:\w+\s){1}\K\w+
  </code></pre>
  
  <p>returns all words</p>
  
  <p>====</p>
  
  <p>With all of the above not working, I thought I would test out some others to see the limitations of the system</p>
  
  <p>Attempting to return the last word:</p>
  
  <pre><code> \w+$
  </code></pre>
  
  <p>returns all words</p>
  
  <p>This leads me to believe that something strange is going on with the start <code>^</code> and end <code>$</code> characters, perhaps the server puts these in automatically if they are omitted? Any more ideas greatly appreciated.</p>