Q:

How I run the replace function one time?

I want the replaceFunction to run only one time. For now works correctly only on first time, E-1 return Ε-1 (APPLE) but when user try to edit text field again system detect
Ε-1 and return Ε-1 (APPLE) (APPLE)..
td.onchange = function(e) {
    this.value = this.value.replace(/(\E-(\d+))/g, replaceFunction);

    function replaceFunction(match) {
        // add additional rules here for more cases
        if (match === "E-1") return "Ε-1 (APPLE)";
        if (match === "E-2") return "Ε-2 (SUMSUNG)";
        .
        .
        .
        if(match === "E-99") return "Ε-99 (LG)";
        return match;
    }
}

How I stop this?

A:

You can use something like this one more condition:
if (match === "E-1" && match !== "Ε-1 (APPLE)") return "Ε-1 (APPLE)";

this can be optimized, if you put the mapping into object:
var map = {
    "E-1": "Ε-1 (APPLE)",
    ...
}

if (map[match] && !map[match] !== match) { return map[match]; }

and for this to work you will need regex that also match the word after in bracket:
var names = ['APPLE', 'SAMSUNG'];

var re = new RegExp('(E-(\\d+))(?! \\((?:' + names.join('|') + ')\\))', 'g');

Yet another solution is to use only array (this will only work if you E-NUM match index in array)
var names = ['APPLE', 'SAMSUNG'];
var re = new RegExp('(E-(\\d+))(?! \\((?:' + names.join('|') + ')\\))', 'g');
// regex explanation, same as yours but \\d is because it's a string
// we create negative look ahead so we check if next text
// after E-1 is not " (" and any of the names.
// we use (?: to group what's inside it's the same as with ()
// but the value will not be captured so there will be
// no param in function for this group
// so this regex will be the same as yours but will not match "E-1 (APPLE)"
// only "E-1"

this.value = this.value.replace(re, replaceFunction);

function replaceFunction(match, eg, num) {
   // convert string to number E starts 
   var i = parseInt(num, 10) - 1;
   if (i <= names.length) {
     return match + ' (' + names[i] + ')';
   }
}

the regex and function can be created outside of the change function, so it don't create new function on each change.

