veronikaaa86

RegexMonFail

Feb 26th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package exams.july2017;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class P03_RegexMon {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.         String input = reader.readLine();
  14.  
  15.         String regexDidimon = "([^A-Za-z\\-]+)";
  16.         String regexBojomon = "([A-Za-z]+)\\-([A-Za-z]+)";
  17.         String regexDashes = "(\\-+)";
  18.  
  19.         Pattern didimonPattern = Pattern.compile(regexDidimon);
  20.         Matcher didimonMatcher = didimonPattern.matcher(input);
  21.  
  22.         Pattern bojomonPattern = Pattern.compile(regexBojomon);
  23.         Matcher bojomonMatcher = bojomonPattern.matcher(input);
  24.  
  25.         Pattern dashesPattern = Pattern.compile(regexDashes);
  26.         Matcher dashesMatcher = dashesPattern.matcher(input);
  27.  
  28.         String currentLine = input;
  29.         String strToRemove = "";
  30.  
  31.         while (true) {
  32.             if (currentLine.length() == 0) break;
  33.  
  34.             if (didimonMatcher.find()) {
  35.                 System.out.println(didimonMatcher.group());
  36.                 strToRemove = didimonMatcher.group();
  37.                 currentLine = currentLine.substring(strToRemove.length(), currentLine.length());
  38.             }
  39.             if (bojomonMatcher.find()) {
  40.                 System.out.println(bojomonMatcher.group());
  41.                 strToRemove = bojomonMatcher.group();
  42.                 currentLine = currentLine.substring(strToRemove.length(), currentLine.length());
  43.             }
  44.             if (dashesMatcher.find()) {
  45.                 strToRemove = dashesMatcher.group();
  46.                 currentLine = currentLine.substring(strToRemove.length(), currentLine.length());
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment