fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Example
  5. {
  6. public static void Main()
  7. {
  8. string phone = "11122233334";
  9.  
  10. string txt = Regex.Replace(
  11. Regex.Replace(phone, @"(^\d{10})(\d)", "$1 ext $2"),
  12. @"(\d{3})(\d{3})(\d{4})", "($1) $2-$3");
  13.  
  14. Console.WriteLine(txt);
  15. }
  16. }
Success #stdin #stdout 0.1s 24272KB
stdin
Standard input is empty
stdout
(111) 222-3333 ext 4