Advertisement
Guest User

02. Extract Sentences by Keyword

a guest
Feb 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Example
  5. {
  6.     public static void Main()
  7.     {
  8.         string word = Console.ReadLine();
  9.         string pattern = $@"(\.|\?|!|)([\w@#$%^&*()\-=+`~\s]+\ {word} [\w\s@#$%^&*()\-=+`~]+)(\.|!|\?|)";
  10.         string input = Console.ReadLine();
  11.  
  12.  
  13.         foreach (Match m in Regex.Matches(input, pattern))
  14.         {
  15.             if (m.Groups[2].Success)
  16.             {
  17.             Console.WriteLine(m.Groups[2].Value.Trim());
  18.             }
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement