Reputation: 23
I have a pre-defined set of words like Horse Pearl House
And I would want my regular expression to match any word contained among those 3.
Example: orse - contained in Horse. Pea - contained in Pearl. Ho - contained in Horse and House.
How do I create a regular expression to achieve this in JavaScript or c#?
I was thinking in this direction.
\b*(Horse|Pearl|House)
Upvotes: 2
Views: 169
Reputation: 831
var arr = ["Horse", "Pearl", "House"];
var string_matched="";
for (var i = 0; i < arr.length; i++)
{
if (/se/gi.test(arr[i])) {
string_matched += ", " + arr[i];
}
}
You will get the matched strings in the string_matched variable.
Upvotes: 1