Advertisement
AmourSpirit

Regex Match Date Time

Oct 7th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1.  
  2. // (19|20|21)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])\s([0-1][0-9]|2[0-3])[:]([0-5][0-9])[:]([0-5][0-9])
  3. //  using System.Text.RegularExpressions;
  4. /// <summary>
  5. ///  Regular expression built for C# on: Wed, Oct 7, 2015, 04:51:18 PM
  6. ///  Using Expresso Version: 3.0.4750, http://www.ultrapico.com
  7. ///  
  8. ///  A description of the regular expression:
  9. ///  
  10. ///  [1]: A numbered capture group. [19|20|21]
  11. ///      Select from 3 alternatives
  12. ///          19
  13. ///              19
  14. ///          20
  15. ///              20
  16. ///          21
  17. ///              21
  18. ///  \d\d
  19. ///      Any digit
  20. ///      Any digit
  21. ///  Any character in this class: [-]
  22. ///  [2]: A numbered capture group. [0[1-9]|1[012]]
  23. ///      Select from 2 alternatives
  24. ///          0[1-9]
  25. ///              0
  26. ///              Any character in this class: [1-9]
  27. ///          1[012]
  28. ///              1
  29. ///              Any character in this class: [012]
  30. ///  Any character in this class: [-]
  31. ///  [3]: A numbered capture group. [0[1-9]|[12][0-9]|3[01]]
  32. ///      Select from 3 alternatives
  33. ///          0[1-9]
  34. ///              0
  35. ///              Any character in this class: [1-9]
  36. ///          [12][0-9]
  37. ///              Any character in this class: [12]
  38. ///              Any character in this class: [0-9]
  39. ///          3[01]
  40. ///              3
  41. ///              Any character in this class: [01]
  42. ///  Whitespace
  43. ///  [4]: A numbered capture group. [[0-1][0-9]|2[0-3]]
  44. ///      Select from 2 alternatives
  45. ///          [0-1][0-9]
  46. ///              Any character in this class: [0-1]
  47. ///              Any character in this class: [0-9]
  48. ///          2[0-3]
  49. ///              2
  50. ///              Any character in this class: [0-3]
  51. ///  Any character in this class: [:]
  52. ///  [5]: A numbered capture group. [[0-5][0-9]]
  53. ///      [0-5][0-9]
  54. ///          Any character in this class: [0-5]
  55. ///          Any character in this class: [0-9]
  56. ///  Any character in this class: [:]
  57. ///  [6]: A numbered capture group. [[0-5][0-9]]
  58. ///      [0-5][0-9]
  59. ///          Any character in this class: [0-5]
  60. ///          Any character in this class: [0-9]
  61. ///  
  62. ///
  63. /// </summary>
  64. public static Regex regex = new Regex(
  65.       "(19|20|21)\\d\\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01]"+
  66.       ")\\s([0-1][0-9]|2[0-3])[:]([0-5][0-9])[:]([0-5][0-9])",
  67.     RegexOptions.Multiline
  68.     | RegexOptions.Compiled
  69.     );
  70.  
  71.  
  72. // This is the replacement string
  73. public static string regexReplace =
  74.       "NewItem.$1 = this.$1;";
  75.  
  76.  
  77. //// Replace the matched text in the InputText using the replacement pattern
  78. // string result = regex.Replace(InputText,regexReplace);
  79.  
  80. //// Split the InputText wherever the regex matches
  81. // string[] results = regex.Split(InputText);
  82.  
  83. //// Capture the first Match, if any, in the InputText
  84. // Match m = regex.Match(InputText);
  85.  
  86. //// Capture all Matches in the InputText
  87. // MatchCollection ms = regex.Matches(InputText);
  88.  
  89. //// Test to see if there is a match in the InputText
  90. // bool IsMatch = regex.IsMatch(InputText);
  91.  
  92. //// Get the names of all the named and numbered capture groups
  93. // string[] GroupNames = regex.GetGroupNames();
  94.  
  95. //// Get the numbers of all the named and numbered capture groups
  96. // int[] GroupNumbers = regex.GetGroupNumbers();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement