Advertisement
Guest User

Extract sentences by keyword

a guest
Feb 9th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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 _2.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.  
  17. string pattern = @"(?:^|[\s|\w]+) word [a-zA-Z0-9]+[\sa-z-0-9]+";
  18.  
  19. var replaced = pattern.Replace("word", word);
  20. var reg = new Regex(replaced);
  21.  
  22. MatchCollection matchCollection = reg.Matches(text);
  23.  
  24. foreach (Match match in matchCollection)
  25. {
  26. Console.WriteLine(match.Groups[0]);
  27. }
  28.  
  29.  
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement