-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
50 lines (47 loc) · 1.59 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string alphaNumeric = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-'";
string input = "Today is Friday. Tommorrow will be saturday, followed by Sunday.";
string pattern = @"[Ss]\S+";
pattern = @"\W";
input = alphaNumeric;
var parser = new RegexTest();
parser.PrintOutMatches(input, pattern);
Console.ReadKey();
}
public class RegexTest
{
public void PrintOutMatches(string input, string pattern)
{
var regex = new Regex(pattern);
var matches = regex.Matches(input);
Console.WriteLine("Input: {0}", input);
Console.WriteLine("Pattern: {0}", pattern);
if (matches == null)
{
Console.WriteLine("No matches found.", input);
return;
}
if (matches != null && matches.Count > 0)
{
Console.WriteLine("Total Match: {0}", matches.Count);
foreach (var match in matches)
{
Console.WriteLine(match);
}
}
return;
}
}
}
}