title: Slicing and Dicing Strings with Regex
body: <p>I'm interested in a Regex pattern that will jump to the first non whitespace character, return that index and then from there the next whitespace character, and return that index. </p>
  
  <p>Essentially, what I am trying to do is pull a word out of a string. But I'd also like to preserve indexes because I need to rebuild that string without the word we just pulled out.</p>
  
  <p>Something of this sort:</p>
  
  <pre><code>var start = txt.search(/\S/); //this gets the index of the first non whitespace character
  var end = txt.search(/\s/); //this gets the index of the first whitespace character
  var word = txt.slice(start,end); //get the word
  txt = txt.slice(end); //update txt to hold the rest of the string
  </code></pre>
  
  <p>The problem with that implementation is if the first whitespace character comes BEFORE the first non whitespace character, we get undesired results.</p>
  
  <p>If .search had a start index that'd be super helpful, but other than that I am stumped. </p>
  
  <p>Trying to word this a bit better:</p>
  
  <p>I need the index of the first non whitespace character, and then the index of the first whitespace character that comes after the first nonwhitespace character. This would allow me to get a single word from a string.  </p>