identificación como para hacer algo asícada partido RegEx en cadena
foreach (Match match in regex)
{
MessageBox.Show(match.ToString());
}
Gracias por cualquier ayuda ...!
identificación como para hacer algo asícada partido RegEx en cadena
foreach (Match match in regex)
{
MessageBox.Show(match.ToString());
}
Gracias por cualquier ayuda ...!
hay un método RegEx.Matches
:
foreach (Match match in regex.Matches(myStringToMatch))
{
MessageBox.Show(match.Value);
}
Para obtener el subcadena coincidente, se utiliza la propiedad Match.Value
, como se muestra arriba.
Primero necesita declarar la cadena que se analizará, y luego el patrón de expresiones regulares. Finalmente en el bucle que tienen a instancia regex.Matches(stringvar)
string stringvar = "dgdfgdfgdf7hfdhfgh9fghf";
Regex regex = new Regex(@"\d+");
foreach (Match match in regex.Matches(stringvar))
{
MessageBox.Show(match.Value.ToString());
}
de MSDN
string pattern = @"\b\w+es\b";
Regex rgx = new Regex(pattern);
string sentence = "Who writes these notes?";
foreach (Match match in rgx.Matches(sentence))
{
Console.WriteLine("Found '{0}' at position {1}",
match.Value, match.Index);
}
Se puede mostrar una entrada y salida de ejemplo? – kennytm
Para aquellos de nosotros que somos demasiado perezosos para buscarlo, y no sabemos: RegularExpressions está en el espacio de nombres System.Text. – amalgamate