-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
37 lines (34 loc) · 1.13 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
using System;
using System.Linq;
using IronRure;
namespace filtering
{
class Program
{
private static readonly string[] BadWords = new[] { "red", "green","blue" };
static void Main(string[] args)
{
var set = new RegexSet(BadWords);
var expressions = BadWords.Select(p => new Regex(p)).ToList();
string line;
while ((line = Console.ReadLine()) != null)
{
var match = set.Matches(line);
if (match.Matched)
{
for (int i = 0; i < match.Matches.Length; i++)
{
if (match.Matches[i])
{
foreach (var found in expressions[i].FindAll(line))
{
line = line.Replace(found.ExtractedString, new string('*', found.ExtractedString.Length));
}
}
}
}
Console.WriteLine(line);
}
}
}
}