I am given two variables, a string [var str] and an array of words [var exceptions]. I am replacing every middle character of every word longer than 3 letters with an asterisk using the following regular expression:
var edited = str.replace(/\B\w\B/g, '*');
For example, the string "This is an example of what I am doing" would be returned as "T**s is an e*****e of w**t I am d***g".
However, I would like to add exceptions to this regular expression. So for example, I am given the array (var exceptions = ["example","doing"]), then I would like the regex to return: "T**s is an example of w**t I am doing"
Does anyone know how to do this? If there is a way to achieve this using regex great, if not I am open to other suggestions.
Many thanks :)