Match words that contain the pattern 'ai' or 'ie' : Regex Match : Regular Expression C# Examples


C# Examples » Regular Expression » Regex Match »

 

Match words that contain the pattern 'ai' or 'ie'









    
using  System;
using  System.Text.RegularExpressions;

class  MainClass  {

    private  static  void  DisplayMatches(string  text,string  regularExpressionString)  {
        Console.WriteLine("using  the  following  regular  expression:  "  +regularExpressionString);
        MatchCollection  myMatchCollection  =  Regex.Matches(text,  regularExpressionString);
        foreach  (Match  myMatch  in  myMatchCollection)  {
            Console.WriteLine(myMatch);
        }
    }

    public  static  void  Main()  {
        string  text  ="put  curtain  pertain  peiu";
        
        Console.WriteLine("Matching  words  that  contain  the  pattern  'ai'  or  'ie'");
        DisplayMatches(text,  @"\S*(ai|ie)\S*");
    }
}
    
   
  
   



Output

Matching words that contain the pattern 'ai' or 'ie'
using the following regular expression: \S*(ai|ie)\S*
curtain
pertain


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Regular Expression
» Regex Match