mardi 20 octobre 2015

Regex.Matches not returning expected

Very quick question with probably easy solution,

Have been search for about 2 hours trying every combination to solve this problem.

Using Regex.Matches I'm under the impression that you would enter something as such:

    private static int CheckForWordMatch(string offer, string item)
    {
        string pattern = @"\b(" + item + ")\b";

        int count = 0;
        count = Regex.Matches(@offer, pattern).Count;

        return count;
    }

Test parameters:

offer = AK47HyperBeastFieldTested item = AK47HyperBeastFieldTested

Im looking for the EXACT word match so that if the item were to be, say, "AK47HyperBeast" it wouldnt return a match count of 2.

What am i doing wrong here?

Aucun commentaire:

Enregistrer un commentaire