T
Tony Johansson
Hi!
The regular expression below match these strings.
string text = "(314).555-4000";
//string text = "314-555-4000";
//string text = "314 555-4000";
One small problem is that if I write the text as follows "(314.555-4000";
it still will match the pattern
So how can I write the regular expression so that if one of the parentesis
is missing it should not match the pattern
string pattern = @"\(?\d{3}\)?[-\s.]\d{3}[-.]\d{4}";
MatchCollection matches = Regex.Matches(text, pattern,
RegexOptions.IgnoreCase |
RegexOptions.ExplicitCapture);
Console.WriteLine("hits is {0}", matches.Count);
//Tony
The regular expression below match these strings.
string text = "(314).555-4000";
//string text = "314-555-4000";
//string text = "314 555-4000";
One small problem is that if I write the text as follows "(314.555-4000";
it still will match the pattern
So how can I write the regular expression so that if one of the parentesis
is missing it should not match the pattern
string pattern = @"\(?\d{3}\)?[-\s.]\d{3}[-.]\d{4}";
MatchCollection matches = Regex.Matches(text, pattern,
RegexOptions.IgnoreCase |
RegexOptions.ExplicitCapture);
Console.WriteLine("hits is {0}", matches.Count);
//Tony