A
A
arti_djeims2017-08-24 13:06:27
JavaScript
arti_djeims, 2017-08-24 13:06:27

How to get a word completely from its stem?

There is a code that replaces the words on the page that I need:

var str = "Successful and Successfully" //предложение
var firstWord = "successful"; //наше ключевое слово для поиска
var word = new RegExp(firstWord, 'gi');
str.replace(word, "");

What this code will do is delete the word Successful in 2 places in the sentence, but leave the ending to the word "ly" in the second case. So, could you help to make sure that we get the whole word and erase it completely, regardless of the fact that there are endings (we would erase it along with the endings).
It would also be cool if we could make a check that if there is a comma or a dot after the word, then we do not attribute the dot as the end of the word and therefore we omit it.
I will be grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D3lphi, 2017-08-24
@arti_djeims

var str = "Successful and Successfully" //предложение
var firstWord = "successful"; //наше ключевое слово для поиска
var word = new RegExp(firstWord + "[a-z]*", 'gi');
str.replace(word, "");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question