var txt = "<p>Пример: 5+15 =двадцать</p>"; var result = txt.replace(/.*?(\d.*?)=.*/, function(a, b){ return (new Function( 'return (' + b + ')' )()); }); alert(result);