Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that reads a keyword and some text from the console and prints all sentences from the text, containing that word. A sentence is any sequence of words ending with '.', '!' or '?'. */
- namespace _04.SentenceExtractor
- {
- using System;
- using System.Text.RegularExpressions;
- class SentenceExtractor
- {
- static void Main(string[] args)
- {
- string keyword = Console.ReadLine();
- string text = Console.ReadLine();
- string pattern = @"\b[A-Z][^.?!]*?\b" + keyword + @"\b.*?[!.?]";
- MatchCollection matches = Regex.Matches(text, pattern);
- Console.WriteLine("Output:");
- foreach (Match match in matches)
- {
- Console.WriteLine(match);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement