2

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)
4

1 回答 1

1
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.

于 2012-12-10T06:37:20.050 回答