I want to replace whole word in a string.
Here is my code
$new_val = $val.replace(/\ba\b/, "");
It replaces a woth blank ,it is working fine but i want to use dynamic value in the place of a
.how to do that?
Fixed version of Shivdhwaj Pandey's answer:
$val = " a b c";
$stringToFind = "a";
var re = new RegExp("\\b" + $stringToFind + "\\b");
$new_val = $val.replace(re, "");
console.log($new_val);