Advertisement
Guest User

02.Extract Sentences by Keyword

a guest
Oct 28th, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _02.ExtractSentencesByKeyWord
  5. {
  6.     class ExtractSentencesByKeyWord
  7.     {
  8.         static void Main()
  9.         {
  10.             string word = Console.ReadLine();
  11.             Regex pattern = new Regex($@"\b[^.?!]+\b {word} \b[^.?!]+\b");
  12.  
  13.             string text = Console.ReadLine();
  14.  
  15.             MatchCollection matches = pattern.Matches(text);
  16.  
  17.             foreach (Match match in matches)
  18.             {
  19.                 string sentence = match.Value.Trim();
  20.                 Console.WriteLine(sentence);
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement