I parse simple json object:
{"phone":"8 920 034-00-88"}
To get phone number i use code below:
string phoneStr = @"{""phone"":""8 920 034-00-88""}";
string searchPattern = @"{\s*""phone""\s*:\s*""(?<phone>.+)""\s*}";
Match match = Regex.Match(phoneStr, searchPattern);
if (match.Success)
Console.WriteLine("Phone number:{0}", match.Groups["phone"].Value);
else
Console.WriteLine("Phone number did not match");
I get result like: '8 920 034-00-88', but i need only digit symbol in phone number without whitespace and '-' like: '89200340088'. Can i get this result use only Regex?
var digits = new string("{\"phone\":\"8 920 034-00-88\"}".Where(char.IsDigit).ToArray());?