mercredi 12 octobre 2016

Regex Match multiple occurences with numbers in string C#

I've been searching for my problem answer, but couldn't find so I write here.

I want to take a string example: = "37513220102304920105590"

and find all matches for numbers of length 11 which starts 3 or 4.

I have been trying to do so:

string input = "37513220102304920105590"
var regex = new Regex("^[3-4][0-9]{10}$");
var matches = regex.Matches(trxPurpose);

// I expect it to have 3 occurances "37513220102", "32201023049" and "30492010559"
// But my matches are empty. 
foreach (Match match in matches)
{
    var number = match.Value;

    // do stuff
}

My question is: Is my regex bad or I do something wrong with mathing?

Aucun commentaire:

Enregistrer un commentaire