title: Using a regex to match a word ending in a comma but not within another word
body: <p>I want to use a regex to achieve two objectives: match a string only when it is a complete word (don't match "on" inside of "contact"), and match strings that end with a comma or period. </p>
  
  <p>This is an example. It is meant to find the string (str2) in str and replace it with the same string surrounded by parenthesis.</p>
  
  <pre><code>while(scan2.hasNext()) {
      String str2 = scan2.next();
      str = str.replaceAll("\\b" + str2 + "\\b", "(" + str2 + ")");
  }
  </code></pre>
  
  <p>It does avoid matching strings within words, but it ignores strings that end in a comma or period.</p>
  
  <p>How would I do this?</p>