C# Extension Method: String - Matches`

CSharp · Console

/Program.cs

// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002168/string-matches

// @nuget: Z.ExtensionMethods

using System;
using System.Text.RegularExpressions;

public class Program
{
	public static void Main()
	{
		string pattern = @"\b\w+es\b";
      	string input = "Who writes these notes?";
		
		// C# Extension Method: String - Matches
      	var matches = input.Matches(pattern);
		
      	foreach (Match match in matches)
		{
			Console.WriteLine("Found '{0}' at position {1}", 
                           match.Value, match.Index);
		}
	}
}
;