CSharp examples for System:String Match
Gets all matches in the given string using the given pattern.
using System.Text.RegularExpressions; using System.IO;/* www .j a v a 2 s . com*/ using System.Collections.Generic; public class Main{ /// <summary> /// Gets all matches in the given string using the given pattern. /// </summary> /// <param name="Input">The string which in the pattern is searched.</param> /// <param name="Pattern">The searched pattern. Must contain exactly one capturing group.</param> /// <returns>The first capturing group's value in each matches.</returns> public static IEnumerable<string> GetMatches(this string Input, string Pattern) { Regex r = new Regex(Pattern); var result = r.Matches(Input); foreach (Match Current in result) { yield return Current.Groups[1].Value; } } }