alexmitev

Regex

Dec 3rd, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 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.   class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             string keyword = Console.ReadLine();
  12.             string userInput = Console.ReadLine();
  13.             string pattern = string.Format(@"([^.!?])+( {0} )([^.!?])*", keyword);
  14.  
  15.             MatchCollection matches = Regex.Matches(userInput, pattern);
  16.  
  17.             foreach(var match in matches)
  18.             {
  19.                 Console.WriteLine(match);
  20.             }
  21.            
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment