title: Regular Expressions to insert "\r" every n characters in a line and before a complete word (basically a wordwrap feature)
body: <p>I'm new to JavaScript and regular expression. I'm trying to automatically format a text document to specific number of characters per line or put a "\r" before the word.</p>
  
  <p>This is functionally similar to Wordwrap found in numerous text editors.</p>
  
  <p>Eg. I want 10 characters per line</p>
  
  <p>Original:My name is Davey Blue.</p>
  
  <p>Modified:My name \ris Davey \rBlue.</p>
  
  <p>See, if the 10th character is a word, it puts that entire word down into a new line.</p>
  
  <p>I'm thinking the following should work to some degree /.{1,10}/ (This should find any 10 characters right?)</p>
  
  <p>Not sure how to go about the rest.</p>
  
  <p>Please help.</p>