function $(id) { return document.getElementById(id); } function cut_or_add(obj) { val = $('get_div').value; replace = val.replace(new RegExp(obj, 'g'), ''); $('get_div').value = replace; // сие вырезает значение obj из val } 

How to determine that the value of obj is missing in val and add it there? I only need to determine its absence. Tell me what the condition will look like based on a regular expression?

    1 answer 1

     !val.match('/regexp/g'); 

    not?

    Well, in your case -

     if(!val.match(new RegExp(obj, 'g'))){ //Отсутствует } 

    True, I think you yourself guessed it

    • Went to juzat) - Palmervan
    • Thank you very much, it works as it should) - Palmervan