title: Regex or javascript 1 word in every X consecutive words
body: <p>I need to come up with some regex or javascript that will as the title says get 1 random word from every X consecutive words.</p>
  
  <p>for e.g I have this piece of text</p>
  
  <p>"In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. Common abbreviations for "regular expression" include regex and regexp."</p>
  
  <p>I would like to regex 1 word every 4 words so from the first four words in the text "In computing, a regular" I would regex out 1 random word e.g computing</p>
  
  <p>The need to do this for the whole text however so for example in the above there are 9 groups of 4 words. I would like to regex out one random word from each group. Hopefully I can make a quick edit in that regex so it can do the same for X word groups as well. X being any number.</p>
  
  <p>I have tried all over to get something that can do this for me but I'm not getting on very well (I am new to both regex and javascript)</p>
  
  <p>I think if I can use javascript to split the text into X groups of words, I can then try to get a random word from each group afterwards.</p>
  
  <p>What I have so far is this: </p>
  
  <pre><code>var split='In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. Common abbreviations for "regular expression" include regex and regexp.'.match(/[^ ]+( +[^ ]+){0,3}/g); 
  </code></pre>
  
  <p>This splits the text with a comma separator into groups of 4 words (or every 3 spaces). The problem is that the separator is a comma so any comma's in the original text are also seen in the output e.g</p>
  
  <pre><code>In computing, a regular,expression provides a concise,and flexible means to,"match" (specify and recognize),strings of text, such,as particular characters, words,,or patterns of characters.,Common abbreviations for "regular,expression" include regex and,regexp.
  </code></pre>
  
  <p>Is there anyway to change that separator to something besides a comma? At least this way I can then try and come up with some regex that can be used on each 4 word group. I thought of maybe replacing the comma after the match but that will replace all the original commas as well of course.</p>
  
  <p>I'm not sure how I will do the random word regex or javascript but having the groups sorted out I think is the first step in the right direction?</p>
  
  <p>Thanks for any help or advice with this, I really appreciate it. Sorry if this is completely straightforward to some of you but I am new do this and I've tried for hours now to come up with some working solution but to no avail.</p>
  
  <p>Peter</p>