Answer the question
In order to leave comments, you need to log in
Did you correctly translate the Python function into JS?
there is a function:
def text_cleaner_fio(text):
text = re.sub( r'[\W]+', ' ', text ) # удаление лишних символов
text = re.sub( r'([А-Я]{1}[а-яё]{0,23} [А-Я]{1}[а-яё]{0,23} [А-Я]{1}[а-яё]{0,23})|( [A-Z]{1}[a-z]{1,23} [A-Z]{1}[a-z]{1,23})$', ' FIO ', text ) # замена учеток
return text
function text_cleaner_fio(text){
text.replace(/[\W]+/, ' '); # удаление лишних символов
text.replace(/([А-Я]{1}[а-яё]{0,23} [А-Я]{1}[а-яё]{0,23} [А-Я]{1}[а-яё]{0,23})|( [A-Z]{1}[a-z]{1,23} [A-Z]{1}[a-z]{1,23})$/, 'FIO'); # замена учеток
return text;
}
Answer the question
In order to leave comments, you need to log in
The peculiarity of regular expressions is that they represent a separate language in which they are written. That is, regular expression in python = regular expression in any other language.
The answer to your question is yes, correct.
You can also combine method calls:
function text_cleaner_fio(text){
return text
.replace(/[\W]+/, ' ') # удаление лишних символов
.replace(/([А-Я]{1}[а-яё]{0,23} [А-Я]{1}[а-яё]{0,23} [А-Я]{1}[а-яё]{0,23})|( [A-Z]{1}[a-z]{1,23} [A-Z]{1}[a-z]{1,23})$/, 'FIO'); # замена учеток
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question