DEV Community

Discussion on: How to find a string, within a string, using Regex

Collapse
 
savagepixie profile image
SavagePixie

Do you have them in an array? That'd be ideal, as you could do something like this:

const getWords = arr => {
   const regEx = /macports?/i
   return arr.filter(x => regEx.test(x))
}

If no array, then forget about the filter, but you can still apply the same principle.

Another way to go would be:

string.includes("macport")

Though you might have to turn the string into lower case for this one.