Advertisement
NelIfandieva

regexProblem_01

Mar 3rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Feb26_2018
  10. {
  11.     class MainClass
  12.     {
  13.         /* The input will consist of a single line, containing the text,
  14.          * that Bojomon and Didimon are going to match. */
  15.  
  16.         public static void Main()
  17.         {
  18.             var patternBojo = @"\b([A-Za-z]+-[A-Za-z]+)\b";
  19.             var patternDidi = @"[^A-Z[a-z-]";
  20.             var input = "^^^^pika-pika^^^^";//Console.ReadLine();
  21.  
  22.             //char[] sep = {'\S'};
  23.             // var inputSplit = input.Split(sep, StringSplitOptions.RemoveEmptyEntries);
  24.             //string separ = @"\w";
  25.             //string[] splitInput = Regex.Split(input, separ);
  26.             //Console.Write(string.Join(", ", splitInput));
  27.             //var inputSplitByDidi = input.Split(patternDidi);
  28.             //Match matchBojo = patternBojo.Match(input);
  29.  
  30.             var matchDidi = Regex.Matches(input, patternDidi);
  31.             var matchBojo = Regex.Matches(input, patternBojo);
  32.  
  33.             Regex didi = new Regex(patternDidi);//patternDidi
  34.             Regex bojo = new Regex(patternBojo);
  35.             bool inputHasDidi = didi.IsMatch(input);
  36.             bool inputHasBojo = bojo.IsMatch(input);
  37.             MatchCollection matchedDidi = didi.Matches(input);
  38.             MatchCollection matchedBojo = bojo.Matches(input);
  39.  
  40.             foreach(var item in input)
  41.             {
  42.                 if (inputHasDidi)
  43.                 {
  44.  
  45.                     foreach (var did in matchedDidi)
  46.                     {
  47.                         Console.Write(did);
  48.                     }
  49.                 }
  50.                 else if (inputHasBojo)
  51.                 {
  52.                     foreach (var boj in matchedBojo)
  53.                     {
  54.                         Console.Write(boj);
  55.                     }
  56.                 }
  57.                 Console.WriteLine();
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement