/([а-яё])/ig 

how to improve this regular expression so that it additionally finds various characters , except for the point (.), underscore (_), dash (-), slash (/), asterisk (*), brackets (). Tried to do at least like this, but does not find anything:

 /([а-яё].(\.\_\-\/\*\(\)))/ig 

    1 answer 1

    All characters except . , _ , / , * , ( and ) :

     /[^\._\-\/\*\(\)]/ 

    In the Russian version of MDN, this is referred to as: "negative or additional character set"

    And an example of removing from the string all characters except those specified:

     var regex = /[^\._\-\/\*\(\)]/g; console.log("aAбБ1!@%#%:;'\"+._-*()[]{}".replace(regex, "")); 

    • why in such an expression $ 1 is returned, rather than a colored character: return el.toUpperCase (). replace (/ [^ \ ._ \ - \ / * () 0-9a-z] / ig, '<span style = "color : red; display: inline-block; background: yellow "> $ 1 </ span> '); - ikar
    • one
      @ikar because you do not have the first group. Wrap [...] in brackets: ([^\._\-\/*()0-9a-z]) . - Regent