How to match words that start with M and ends with e in a string with C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

class Program
{
    public static void WordsMatchWith(string str, string expr) {
        MatchCollection mc = Regex.Matches(str, expr);

        foreach (var word in mc)
            Console.WriteLine(word);
    }
    static void Main() {
        string str = "Marquee C# make net Make c programming m Mixable M Me";

        WordsMatchWith(str, @"\bM\S*e\b");
    }
}



/*
run:

Marquee
Make
Mixable
Me

*/

 



answered Oct 27, 2022 by avibootz
...