Key = 'Test1'; alert( 'Test1.Test2'.replace( new RegExp( '(^|\\W)(' + Key + ')(\\W)' ), "$1Test2$3" ) );