Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- public class PhoneNumbers
- {
- public static void Main()
- {
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "END")
- {
- break;
- }
- sb.Append(input);
- }
- const string pattern = @"(?<name>[A-Z][a-zA-Z]*)[^a-zA-Z+]*?(?<phone>\+?[0-9][0-9.() \-\/]*[0-9])";
- Regex regex = new Regex(pattern);
- var matches = regex.Matches(sb.ToString());
- if (matches.Count == 0)
- {
- Console.WriteLine("<p>No matches!</p>");
- return;
- }
- Console.Write("<ol>");
- foreach (Match match in matches)
- {
- string phone = Regex.Replace(match.Groups["phone"].Value, @"[^+0-9]+", string.Empty);
- Console.Write(
- "<li><b>{0}:</b> {1}</li>",
- match.Groups["name"],
- phone);
- }
- Console.Write("</ol>");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement