Regex get more than one occurrence in a string

4

I have my regex (\d{2}) .

And I have my string 12 hoje vai 45 na serra pelada 55 ou 75 .

How do I get my regex to get all occurrences of the string? She's just getting the last one.

    
asked by anonymous 13.03.2015 / 19:11

1 answer

3

(\d{2})* to zero or more occurrences. (\d{2})+ for one or more occurrences.

See a test here .

To iterate over all occurrences, use:

foreach (Match m in Regex.Matches("12 hoje vai 45 na serra pelada 55 ou 75", "(\d{2})*")) 
{
    // m.Value mostra o valor encontrado, m.Index o índice na lista de 
    // expressões encontradas.
}

The reference is here .

    
13.03.2015 / 19:19