Answer the question
In order to leave comments, you need to log in
How to get the first and last characters of a word from a regular expression in Javascript?
The console shows that the variables are not defined.
let regularBadWordsArray = [
'слово-1',
'слово-2'
];
for (let i = 0; i < regularBadWordsArray.length; i++) {
let regularBadWord = new RegExp(
'\\B' + '[а-яА-Я]*' + regularBadWordsArray[i] + '[а-яА-Я]*' + '\\B',
'gi'
);
// Первый и последний символы
let rbwFirstLetter = regularBadWord[0];
let rbwLastLetter = regularBadWord[-1];
console.log(rbwFirstLetter);
console.log(rbwLastLetter);
}
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