Find each RegEx match in string

后端 未结 3 1853
南旧
南旧 2020-12-18 19:44

id like to do something like

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

Thanks for any help...!

3条回答
  •  独厮守ぢ
    2020-12-18 20:16

    You first need to declare the string to be analyzed, and then the regex pattern. Finally in the loop you have to instance regex.Matches(stringvar)

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

提交回复
热议问题