<script> a="asdand andor and ope(and)and asd and(1)"; b=a.replace(/(\b)and(\b)/g,"$1&&$2"); console.log(b); alert(b); </script>