-Annie-

MatchDateUsingRegex

Jun 9th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. namespace MatchDateUsingRegex
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.  
  6.     public class MatchDateUsingRegex
  7.     {
  8.         public static void Main()
  9.         {
  10.             string text = "Today is 2016-06-09";
  11.             string pattern = @"\d{4}-\d{2}-\d{2}";
  12.             Regex regex = new Regex(pattern);
  13.             bool containsValidDate = regex.IsMatch(text);
  14.  
  15.             Console.WriteLine(containsValidDate); //true
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment