I seem to have confused a lot of people with this question so let me state what I want to do as simply as I can.
I want to search a text string for words that begin with "mak", "mind" and "mass" and end with either nothing extra or "e" or "er". That would be "mak", "make", "maker", "mind", "minde", "minder", "mass", "masse", "masser".
I am trying to match certain words in a text if they start with specific letters and end with specific letters. I am using the following regex:
aray = ['mak','mind', 'mass'];
for(i=0; i < aray.length; i++){
searchTerm = new RegExp(
"\\b" + aray[i] + "\\b|" +
"\\b" + aray[i] + "en\\b|" +
"\\b" + aray[i] + "er\\b");
word = testText.match(searchTerm, "gi");
}
The problem is that when the first instance is matched the other instances are not searched for. Could someone point me in the right direction. Any help would be greatly appreciated.
This question has been flagged as a duplicate but the other question does not answer the points I am having difficulties with.