Advertisement
LardaX

Extract-Sentences-by-Keyword-100/100

Oct 21st, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Extract_Sentences_by_Keyword
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string word = Console.ReadLine();
  15.             string text = Console.ReadLine();
  16.             string pattern = $@"(({word}[^a-zA-Z0-9]|(\w+[^a-zA-Z0-9!\.\?!]*[^a-zA-Z0-9]))+{word}([^a-zA-Z0-9]\w+[^a-zA-Z0-9!\.\?!]*)+)(\.|!|\?)";
  17.  
  18.             Regex regex = new Regex(pattern);
  19.             MatchCollection collection = regex.Matches(text);
  20.  
  21.             foreach (Match sentence in collection)
  22.             {
  23.                 Console.WriteLine(sentence.Groups[1]);
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement