There is a line in which you need to replace all if with replace_if, while the location of this if can be anything, and if it is part of another word, then you don’t need to replace ...

Some replacement examples

if(){ ... else if(){ ... 

Some examples when it is not necessary to replace

 var myif = function(){ ... if24 = 24; 

I don’t know what regular expression you need to write to work correctly

    1 answer 1

    Just try to find the word along the border:

     var str = 'if(){ ... else if(){ ... var myif = function(){ ... if24 = 24;'; console.log(str.replace(/\b(if)\b/g, 'replace_if')); 

    Result:

     replace_if(){ ... else replace_if(){ ... var myif = function(){ ... if24 = 24; 
    • yeah, what you need, thanks a lot ... the solution turns out to be easier than you could imagine :) - arkadij_ok