Answer the question
In order to leave comments, you need to log in
How to fix regular expressions in JS?
Good afternoon, very weak in regular expressions. Help fix them)
I need to:
Answer the question
In order to leave comments, you need to log in
newValue = newValue.replace(/[^а-яА-ЯЁё\s\-]/gi, ''); // дефис не был экранирован: он - тоже спецсимвол
newValue = newValue.replace(/^[\s\-]+/g, '');
newValue = newValue.replace(/[\s\-]+$/g, '');
newValue = newValue.replace(/\s{2,}/g, ' '); // Заменялись все символы, а нужно от двух. Заменялось на пустую строку, а надо на пробел
newValue = newValue.replace(/\-{2,}/g, '-'); // И то же самое для дефисов
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question