Match collection problem in regular expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • w8in4response
    New Member
    • Jul 2014
    • 1

    Match collection problem in regular expression

    I have few user inputs which I am trying to compare via MatchCollection with different patterns I have i.e

    Code:
        string user = "\b(?:I|would|like|to|see|id|of|bought|good)\b";
        
    
    but When I am matching string 
    
        string pattern = "^(?=.*\bgoods?|items?|things?\b)(?=.*\bbought\b)(?=.*\bid\b)(?=.*\btest\b).*$";
    
        MatchCollection mat = Regex.Matches(pattern , user );
    
        foreach (var item in mat)
        {
            Console.WriteLine(item.ToString());
        }
    When matching the two above, the match collection only yields/collects match for (id, bought) but ignores "goods" from the first block of pattern. It seems to be ignoring **?** mentioned at the end of every word goods?|items?|t hings?.

    Any suggestions.


    Thanks
    Last edited by Rabbit; Jul 7 '14, 12:26 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...