Posted By

rtipton on 10/22/09


Tagged

regex regular expressions


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vali29
khouser
franksmile0310


Regular Expressions Sample


 / Published in: C#
 

  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace RegularExpressions
  6. {
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. //-- Take input value and if it is in lastname, firstname format echoes firstname lastname to the console
  12. string userName = Console.ReadLine();
  13. Regex re = new Regex("(\\w+),\\s(\\w+)");
  14. userName = re.Replace(userName, "$2 $1");
  15. Console.WriteLine(userName);
  16.  
  17. //-- Take input value and if it is in mm/dd/yyyy format echoes yyyy/mm/dd to the console
  18. string curDate = Console.ReadLine();
  19. Regex reDate = new Regex("(\\d{2})/(\\d{2})/(\\d{4})");
  20. curDate = reDate.Replace(curDate, "$3/$1/$2");
  21. Console.WriteLine(curDate);
  22. }
  23. }
  24. }

Report this snippet  

You need to login to post a comment.