sam
sam

Reputation: 13

regular expression to match numbers of length 2 from given string

How can I create a regular expression that will match numbers of length 2 from a given string.

Example input:

givenpercentage@60or•70and 8090

Desired output:

60 70 80 90

Upvotes: 0

Views: 98

Answers (1)

Oscar Bralo
Oscar Bralo

Reputation: 1907

Try this:

string x = "givenpercentage@60or•70and 8090";
Regex r = new Regex(@"\d{2}");
foreach(Match m in r.Matches(x))
{
     string temp = m.Value;
     //Do something
} 

\d -> only numbers

{2} -> 2 numbers only

Output will be:

60 70 80 90 

Upvotes: 1

Related Questions