Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Oh_My_Girl
- {
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- class OhMyGirl
- {
- static void Main(string[] args)
- {
- string keyPattern = GetKeyPattern();
- StringBuilder text = new StringBuilder();
- string inputLine = Console.ReadLine();
- while (inputLine != "END")
- {
- text.Append(inputLine);
- inputLine = Console.ReadLine();
- }
- StringBuilder result = new StringBuilder();
- MatchCollection matches = Regex.Matches(text.ToString(), keyPattern);
- foreach (Match match in matches)
- {
- result.Append(match.Groups[1].Value);
- }
- Console.WriteLine(result);
- }
- private static string GetKeyPattern()
- {
- string key = Console.ReadLine();
- StringBuilder sb = new StringBuilder();
- if (!char.IsLetterOrDigit(key[0]) && !char.IsWhiteSpace(key[0]))
- {
- sb.Append('\\');
- }
- sb.Append(key[0]);
- for (int i = 1; i < key.Length - 1; i++)
- {
- if (char.IsDigit(key[i]))
- {
- sb.Append("[0-9]*");
- }
- else if (char.IsUpper(key[i]))
- {
- sb.Append("[A-Z]*");
- }
- else if (char.IsLower(key[i]))
- {
- sb.Append("[a-z]*");
- }
- else if (char.IsWhiteSpace(key[i]))
- {
- sb.Append("\\s");
- }
- else
- {
- sb.Append('\\').Append(key[i]);
- }
- }
- if (!char.IsLetterOrDigit(key[key.Length - 1]) &&
- !char.IsWhiteSpace(key[key.Length - 1]))
- {
- sb.Append('\\');
- }
- sb.Append(key[key.Length - 1]);
- return (sb + "(.{2,6})" + sb);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement