title: JavaScript RegEx to replace words starting with # in a string
body: <p>I am using the below function to replace words beginig with # from the string, with variables of exact same name from the extra_data object.</p>
  
  <pre><code>var messageString = "The folder #folder_name was removed from the workspace #workspace_name by #user_name"
  var re = /(?:^|\W)#(\w+)(?!\w)/g, match;
  while (match = re.exec(messageString)) {
    messageString = messageString.replace(match[0],extra_data[match[1]]);
    console.log("I am here---------------------------------------------&gt;1");
    console.log(messageString);
  }
  </code></pre>
  
  <p>Console log</p>
  
  <pre><code>I am here---------------------------------------------&gt;1
  The folder23545 was removed from the workspace #workspace_name by #user_name
  I am here---------------------------------------------&gt;1
  The folder23545 was removed from the workspace127 by #user_name
  </code></pre>
  
  <p>The above code replaces only 2 instances and sometimes eats up white space also as you can see at workspace127.
  What am i doing wrong?</p>