Cómo: Utilizar expresiones regulares para buscar coincidencias simples (C++/CLI)

En el siguiente ejemplo de código se utilizan expresiones regulares para buscar coincidencias exactas de subcadenas.La búsqueda se realiza mediante el método IsMatch estático, que toma dos cadenas como entrada.La primera corresponde a la cadena que se va a buscar y la segunda corresponde al modelo que se va a buscar.

Ejemplo

// regex_simple.cpp
// compile with: /clr
#using <System.dll>

using namespace System;
using namespace System::Text::RegularExpressions;

int main()
{
   array<String^>^ sentence = 
   {
      "cow over the moon",
      "Betsy the Cow",
      "cowering in the corner",
      "no match here"
   };
    
   String^ matchStr = "cow";
   for (int i=0; i<sentence->Length; i++)
   {
      Console::Write( "{0,24}", sentence[i] );
      if ( Regex::IsMatch( sentence[i], matchStr,
                     RegexOptions::IgnoreCase ) )
         Console::WriteLine("  (match for '{0}' found)", matchStr);
      else
         Console::WriteLine("");
   }
   return 0;
}

Vea también

Otros recursos

Expresiones regulares de .NET Framework

.NET que programa en Visual C++