Trouver chaque correspondance RegEx dans la chaîne

j’aime faire quelque chose comme

foreach (Match match in regex) { MessageBox.Show(match.ToSsortingng()); } 

Merci pour toute aide…!

Il existe une méthode RegEx.Matches :

 foreach (Match match in regex.Matches(mySsortingngToMatch)) { MessageBox.Show(match.Value); } 

Pour obtenir la sous-chaîne correspondante, utilisez la propriété Match.Value , comme indiqué ci-dessus.

de MSDN

  ssortingng pattern = @"\b\w+es\b"; Regex rgx = new Regex(pattern); ssortingng sentence = "Who writes these notes?"; foreach (Match match in rgx.Matches(sentence)) { Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index); } 

Vous devez d’abord déclarer la chaîne à parsingr, puis le motif regex. Enfin, dans la boucle, vous devez par exemple regex.Matches(ssortingngvar)

 ssortingng ssortingngvar = "dgdfgdfgdf7hfdhfgh9fghf"; Regex regex = new Regex(@"\d+"); foreach (Match match in regex.Matches(ssortingngvar)) { MessageBox.Show(match.Value.ToSsortingng()); }