title: Find and replace exact word in long string
body: <p>Below is my string : </p>
  
  <pre><code>api/Node-1/{Node-1}/Node-1-1/{Node-1-1}
  </code></pre>
  
  <p><strong>Search Term :</strong>  Node-1</p>
  
  <p><strong>Replace with :</strong> Learning</p>
  
  <p><strong>Expected output :</strong></p>
  
  <pre><code>api/Learning/{Learning}/Node-1-1/{Node-1-1}
  </code></pre>
  
  <p>Now here the problem is Node-1 is matching with other Node-1-1 also but I want exact word matching and replacement.</p>
  
  <p>I have tried lots of options but none of them is working for me.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> function replaceAll(str, find, replace) {
          return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
      }
  
      function escapeRegExp(str) {
          return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
      }
      
      console.log(replaceAll('api/Node-1/{Node-1}/Node-1-1/{Node-1-1}','Node-1','Learning'));
      
      
      var  replaceStr = 'Node-1';
      console.log( 'api/Node-1/{Node-1}/Node-1-1/{Node-1-1}'.replace(new RegExp("\\b"+replaceStr+"\\b","gi"),"Learning"));
      
      console.log( 'api/Node-1/{Node-1}/Node-1-1/{Node-1-1}'.replace(/\bNode-1\b/g,'Learning'));</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Update :</strong>  This question is not duplicate as my first answer is taken from this <a href="https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript">reference</a> only  which is not working with my input case.</p>