Extract phone numbers from string using regular expression

Posted by Santosh4u under C# on 1/8/2014 | Points: 10 | Views : 1616 | Status : [Member] | Replies : 1
Hi
How do i extract phone numbers from a string using regular expression.

Ex: string Content = "this is string declaration , i have to get this phone number 9902007447 from the string and other 9906007887 test sasa +919087654343 tst sa 919800762222"

Output:
9902007447,9906007887 ,+919087654343 ,919800762222

Thanks
Santosh




Responses

Posted by: kgovindarao523-21772 on: 1/8/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Here is the code: Please Mark as answer if you satisfied

string Content = "this is string declaration , i have to get this phone number 9902007447 from the string and other 9906007887 test sasa +919087654343 tst sa 919800762222";
string[] numbers = Regex.Split(Content, @"[a-zA-Z ,]+");
foreach (string item in numbers)
{
if (!string.IsNullOrEmpty(item))
{
Console.WriteLine(item);

}
}


Thank you,
Govind

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response