stefan1919

sentenceWithWord

Oct 2nd, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace ConsoleApplication3
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string inputWord = Console.ReadLine();
  15.             string input = Console.ReadLine();
  16.             string pattern = string.Format(@"[\w\s]+{0}[\w\s]+[.!?](?=\s)|{1}[\w\s]+[.!?](?=\s)", inputWord, inputWord);
  17.             Regex regex = new Regex(pattern);
  18.             foreach (var item in regex.Matches(input))
  19.             {
  20.                 Console.WriteLine(item);
  21.             }
  22.  
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment