Answer the question
In order to leave comments, you need to log in
How to count the number of characters of a word from a regular expression in Javascript?
It is necessary that words containing characters from the array are replaced with stars. But the character count does not work: the variable is not defined.
window.onload = function() {
s = document.body.innerHTML;
let abc = 'abc';
let regularBadWordsArray = [
'слово-1',
'слово-2'
];
for (let i = 0; i < regularBadWordsArray.length; i++) {
let regularBadWord = new RegExp(
'\\B' + '[а-яА-Я]*' + regularBadWordsArray[i] + '[а-яА-Я]*' + '\\B',
'gi'
);
s = s.replace(regularBadWord, '*'.repeat(regularBadWord.length));
console.log(regularBadWord.length);
}
document.body.innerHTML=s;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question