title: How do I find words starting with a specific letter?
body: <p>I want to find words which start with a specific letter in a string using the following code. The specific letter would be supplied by the user in a text box.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;input id="srch" type="text" /&gt;
  &lt;button onClick=searchword()&gt;Search&lt;/button&gt;
  
  &lt;p id="wrd" &gt; hallo, this is a test john doe .
  Another tea house pole.
  &lt;/p&gt;
  
  &lt;/body&gt;
  
  &lt;script&gt;
  
  function searchword() {
  
  var s = document.getElementById("wrd").innerHTML;
  var p= document.getElementById("srch").value;
  
  var regx = new RegExp("(?:^|\W)" + p + "(\w+)(?!\w)","gi");
  
  var re = regx, match, matches = [];
  
  while (match = re.exec(s)) {
    matches.push(match[0]);
  }
  alert(matches);
  
  
  }
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>