CSharp · Console
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string procurar = "gato";
string nomes = "gato gato gato gato gato gato";
MatchCollection matches = Regex.Matches(nomes, procurar);
foreach (Match match in matches)
{
Console.WriteLine(string.Format("[{0}] >> posição {1}", procurar, match.Index));
}
Console.WriteLine(string.Format(">> Achado '{0}' nomes ", matches.Count));
}
}