Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ForDZ
- {
- class pr_13_9
- {
- public static void Task()
- {
- string[] input = {
- "Hello, I am a string.",
- "This program is free-software; you can copy it.",
- "This program is free-software; you can copy it.",
- "This program is Free-software; you can copy it.",
- "In his house at Rl-yeh dead Cthulhu waits dreaming.",
- "Ph-nglui mglw-mafh Cthulhu R-lyeh wgah-nagl fhtagn.",
- "Is this string work.",
- "First test text. Is it work.",
- };
- string abbreviation = "([A-Z]+)";
- string first_latter_big = "(([A-Z])([a-z]*))";
- string first_latter_low = "([a-z]+)"; ;
- string word_first_part = "(" + first_latter_big + "|" + first_latter_low + ")";
- string word_second_part = "((-" + first_latter_low + ")?)";
- string lower_word = "(" + word_first_part + word_second_part + ")";
- string first_lower_word = "(" + first_latter_big + word_second_part + ")";
- string word = "(" + abbreviation + "|" + lower_word + ")";
- string first_word = "(" + abbreviation + "|" + first_lower_word + ")";
- string separators = @"((( - ){1})|((, ){1})|((; ){1})|((, - ){1})|(( ){1}))"; //"((;)|(((,)?)(( ){1})((- )?)))";
- string final = @"((...)|(\?)|(!)|(.))";
- string sentence = "(" + first_word + "(" + separators + word + ")*" + final + ")";
- string expression = "^(" + sentence + "(( )" + sentence + ")*)$";
- Regex regex = new Regex(expression);
- test(regex, input);
- }
- static void test(Regex regex, string[] inp)
- {
- foreach (string s in inp)
- {
- string t = regex.Match(s).Value;
- //Console.WriteLine($"> {s} ({s.Length}) -> {t} ({t.Length}) : {s.Length == t.Length}");
- Console.WriteLine($"> {s} -> {(s.Length == t.Length ? "YES" : "NO")}");
- }
- Console.WriteLine();
- Console.WriteLine();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- pr_13_9.Task();
- Console.WriteLine("\n\nend.");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement