I know there are plenty of questions regarding RegEx, but I have been searching for at least three days and I cannot find a solution for my problem.
Giving a title of a product I need to extract some information. So in order to do it I am provided with a list of words, so far so good. But the thing is I need to extract a number that will come before any of the words in the list.
Example of list:
const words = ['temp', 'temperature', 'temperatures', 'degrees', 'heat', 'heating']
So far what I have achieved is giving a regEx find some information:
const textToSearch = 'Hair Dryer, 32JVT slopehill Professional Salon Negative Ions Hair Blow Dryer Powerful 1800W for Fast Drying, Lightweight Bioceramic with 3 Heating / 2 Speed/Cool Button, Magnetic Concentrator and Diffuser'
const regex = /(\d+(temp|\s(temp)|temperature|\s(temperature)|degrees|\s(degrees)|heat|\s(heat)|heating|\s(heating)))/g
const found = textToSearch.match(regex);
if (found) {
console.log(found[0]);
}
But the expected output is being for example '32JVT'
and not 3 Heating
Also I don't know how to enter the full list that a I am receiving from my API, as this list will vary and change.
Other problems that might appear are that maybe the word is followed by a symbol like a /
or any other and I don't know how this will mess with the regular expression.