Gr(a|e)y

using System;
using System.Text.RegularExpressions;

public class MainClass {
public static void Main() {

Regex n = new Regex(“Gr(a|e)y”);
MatchCollection mp = n.Matches(“Green, Grey, Granite, Gray”);
for (int i = 0; i < mp.Count; i++) { Console.WriteLine("Found '{0}' at position {1}",mp[i].Value, mp[i].Index); } } } [/csharp]

((an)|(in)|(on))

using System;
using System.Text.RegularExpressions;

public class MainClass {
public static void Main() {

Regex p = new Regex(“((an)|(in)|(on))”);
MatchCollection mn = p.Matches(“King, Kong Kang”);
for (int i = 0; i < mn.Count; i++) { Console.WriteLine("Found '{0}' at position {1}",mn[i].Value, mn[i].Index); } } } [/csharp]

Regex and letter case

using System;
using System.Text.RegularExpressions;

public class MainClass {
public static void Main() {

Regex q = new Regex(” in “);
MatchCollection mm = q.Matches(“IN at in or”);
for (int i = 0; i < mm.Count; i++) { Console.WriteLine("Found '{0}' at position {1}",mm[i].Value, mm[i].Index); } } } [/csharp]

Position and index

   
 
using System;
using System.Text.RegularExpressions;


class MatchingApp {
    static void Main(string[] args) {
        Regex r = new Regex("in");
        Match m = r.Match("Matching");
        if (m.Success) {
            Console.WriteLine("Found &#039;{0}&#039; at position {1}",m.Value, m.Index);
        }
    }
}